pytest-dev / pytest-dev/pytest-html
Pytest-html plugin throws misleading error if log filepath has unsupported special characters for underlying OS
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 779
- Forks
- 260
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
This is related to pytest throwing misleading exception when log filepath contains special characters that are not supported by Windows OS in filenames.
Below is the exception that I got-
Traceback (most recent call last):
File "C:\Users\admin\mtarun\vmware\code\mangle-yaan-service\test_runner.py", line 693, in <module>
main()
File "C:\Users\admin\mtarun\vmware\code\mangle-yaan-service\test_runner.py", line 646, in main
pytest_status = run_pytest(pytest_cmdline, run_id=args.run_id)
File "C:\Users\admin\mtarun\vmware\code\mangle-yaan-service\test_runner.py", line 330, in run_pytest
status = pytest.main(*args, **kwargs)
File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python3
9\site-packages\_pytest\config\__init__.py", line 124, in main
ret = config.hook.pytest_cmdline_main(
File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python3
9\site-packages\pluggy\hooks.py", line 286, in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python3
9\site-packages\pluggy\manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python3
9\site-packages\pluggy\manager.py", line 84, in <lambda>
self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python3
9\site-packages\pluggy\callers.py", line 208, in _multicall
return outcome.get_result()
File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python3
9\site-packages\pluggy\callers.py", line 80, in get_result
raise ex[1].with_traceback(ex[2])
File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python3
9\site-packages\pluggy\callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python3
9\site-packages\_pytest\main.py", line 240, in pytest_cmdline_main
return wrap_session(config, _main)
File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python3
9\site-packages\_pytest\main.py", line 228, in wrap_session
config.hook.pytest_sessionfinish(
File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python3
9\site-packages\pluggy\hooks.py", line 286, in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python3
9\site-packages\pluggy\manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python3
9\site-packages\pluggy\manager.py", line 84, in <lambda>
self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python3
9\site-packages\pluggy\callers.py", line 203, in _multicall
gen.send(outcome)
File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python3
9\site-packages\_pytest\terminal.py", line 716, in pytest_sessionfinish
outcome.get_result()
File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python3
9\site-packages\pluggy\callers.py", line 80, in get_result
raise ex[1].with_traceback(ex[2])
File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python3
9\site-packages\pluggy\callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python3
9\site-packages\pytest_html\plugin.py", line 614, in pytest_sessionfinish
self._save_report(report_content)
File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python3
9\site-packages\pytest_html\plugin.py", line 588, in _save_report
with open(self.logfile, "w", encoding="utf-8") as f:
OSError: [Errno 22] Invalid argument: 'C:\\Users\\admin\\mtarun\\vmware\\code\\mangle-yaan-service\\logs\\mangle-yaan-test-report
-13Aug2021_14:39:57.296895.html'
Ideally, pytest-html should check if there are any unsupported characters in log filepath and throw more informative exception for the same. Can we get a list of special characters that are not supported by specific OS in filenames using any python library? If yes, then we can add a check for log filepath if it has any such special characters that are not supported by underlying OS
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in pytest_html/plugin.py at pytest_sessionfinish and _save_report, where the report is opened at the configured logfile path. Reproduce the Windows invalid-filename case shown in the traceback, then verify that unsupported path characters produce a more informative error and that normal paths still save the report.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100