Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to find the report location from within tests? (To ensure images are located correctly) #824

Open
cc-stjm opened this issue Jul 25, 2024 · 1 comment

Comments

@cc-stjm
Copy link

cc-stjm commented Jul 25, 2024

I see that when adding an image with a relative path, it needs to be relative to the output report HTML.

From the command line, it's possible to run e.g. pytest --html ../report.html - is there any way to be able to get this path from within a test? That would allow me to save images to an appropriate relative path.

(I can't use absolute paths as I want to be able to copy the report & its assets to CI)

@cc-stjm
Copy link
Author

cc-stjm commented Jul 25, 2024

In case it helps anyone, I've found a workaround:

in conftest.py:

_htmlpath = None

def pytest_html_report_title(report):
    global _htmlpath
    _htmlpath = report.config.getoption("htmlpath")

@pytest.fixture
def htmlpath():
    return _htmlpath

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant