Add expanding the environment variables in csspath
Custom CSS (Cascasding Style Sheets) can be passed on the command line using the --css option In the current realization pytest-html checks existing of the css file with the next code
for csspath in config.getoption("css"):
if not Path(csspath).exists():
missing_css_files.append(csspath)
Сould you add the ability to use environment variables in the css file path? This has already been implemented for html path in HTMLReport class by os.path.expandvars
It would look like:
for csspath in config.getoption("css"):
absolute_css_path = Path(os.path.expandvars(csspath)).expanduser().absolute()
if not absolute_css_path.exists():
missing_css_files.append(absolute_css_path)
I'll look into it.
Ok, I've started something.
Questions:
- Why does the path have to be absolute?
- Are you using "--self-contained-html"?
- Could you provide a specific use-case? I'll use that to create a test.
ping @Laymik0o
Hi @BeyondEvil,
- The absolute path is not mandatory, just a first idea. You can remove it and it will work the same
- Yes, I do
- Tests can be divided into suites or features and have a complex folder structure. If pytest is launched for some specific module that placed deep in the structure, the described problem may occur. I first faiced it when I worked through PyCharm and, out of habit, launched the module with tests through Right Click - Run "Python tests in ..."
Example of structure:
/tests
/feature1
/smoke_suite
__init__.py
i_want_run_these_tests.py
i_dont_want_to_run_it_now.py
/outdated_tests_but_still_keep_it
/feature2
/feature3
conftest.py
pytest.ini
pytest_style.css
Pytest has the next args
--html=%LOCALAPPDATA%/temp/tests_report.html --self-contained-html --css=pytest_style.css
So, if I run directle i_want_run_these_tests.py module then I will get error with "missing css files" because it will try to search css in smoke_suite folder If csspath could include system variables, then I would simply specify the path to the working directory where the file is located
Example:
--html=%LOCALAPPDATA%/temp/tests_report.html --self-contained-html --css=%TESTS%/pytest_style.css
A small note for those who run into this problem, can be useful As a workaround I add the following code to conftest.py
def pytest_configure(config):
config.option.css[0] = os.path.join(os.path.dirname(__file__), config.option.css[0])