prashanth-sams / pytest-html-reporter

Generates a static html report based on pytest framework
MIT License
117 stars 37 forks source link

How to store pytest-html-reporter generated report to a custom location #228

Open xiaoguren opened 1 year ago

xiaoguren commented 1 year ago

I am using pytest-html-reporter 0.2.9 plugin to generate execution reports. when i pass the command line argument "--html-report=./report/report.html" directly i am able to get the report in the given location.

I want to store the report in a seperate location with execution date(YYYYMMDD) as folder name and inside report_HHMM.html as the report name

This is the logic i am currently using

@pytest.hookimpl(tryfirst=True) def pytest_configure(config): time_var = datetime.datetime.now()

create report target dir

reports_dir = Path('reports', time_var.strftime('%Y%m%d'))
reports_dir.mkdir(parents=True, exist_ok=True)
# line to be add for addopts
args = f"--html-report=./{reports_dir}/report_{time_var.strftime('%H%M')}.html"
config.addinivalue_line("addopts", args)
print("inside config function",config.getini("addopts"))

this is my pytest.ini file [pytest] pythonfiles = test pythonfunctions = test python_classes = *Tests addopts =

using config.getini("addopts") i am able to see the report path getting added to the addopts,but there are no reports getting added to the created directory

GambetaClub commented 10 months ago

Could you solve this? I want to do the same