barath kowsigan
barath kowsigan

Reputation: 19

auto generation of html report in pytest without commanline arguments

I am using pytest-html plugin. When arguments is passed in command line html report is generated. Need to create html report automatically and the html report link should be displayed in terminal.

Upvotes: 1

Views: 3158

Answers (3)

User
User

Reputation: 4211

Alternative option, just like Nizar's answer

def pytest_cmdline_preparse(config, args):
    config.option.htmlpath = "my-report.html"
    config.option.self_contained_html = True

Upvotes: 0

Nizar Malangadan
Nizar Malangadan

Reputation: 141

You can do this by writing the pytest_cmdline_preparse() hook in the file conftest.py

def pytest_cmdline_preparse(config, args):
    html_file = func_to_generate_html_filename()
    print('HTML report file:', html_file)
    args.extend(['--html', html_file, '--self-contained-html'])

Upvotes: 2

Amit
Amit

Reputation: 20456

You can put the cmdline argument in the pytest.ini file in the root directory

$ cat pytest.ini
[pytest]
addopts = --html=report.html --self-contained-html

Upvotes: 4

Related Questions