pytest
pytest copied to clipboard
[FR] Support for env-dependent `filterwarnings` entries
For example, if I want to add ignore for the deprecation warning that only happens on Python 3.5 and POSIX, I want some entries to only apply to that. The example pseudosyntax:
filterwarnings =
error
ignore::DeprecationWarning; python_version == '3.5' and sys_platform != 'Windows'
(that is completely made up after the env markers but hopefully, you've got the idea)
This seems a bit too specialized, i.e. I am not sure the usefulness is worth the maintenance/documentation overhead.
It can be implemented in code though by throwing the following in a conftest.py:
def pytest_runtestloop(session):
if (3, 5) <= sys.version_info < (3, 6) and sys.platform != 'win32':
session.add_marker(pytest.mark.filterwarnings('ignore::DeprecationWarning'))
Though it's not as nice as having everything in the ini file.
Ah, I didn't think about that... Thanks! OTOH yeah, spreading this across multiple places may be confusing but should be easily fixable by adding a comment with pointers to the ini file...
Though, I do think that documenting such recipe would be beneficial.
I run into the need of this, too, e.g. we regularly see warnings on windows relating to int conversions that never a problem on other platforms (or if they ever pop up, that's a warning I want to notice), and thus I would prefer not to add a blanket ignore but an OS specific one. I'll go ahead with the conftest workaround, but agree with the above that it would be nice to keep everything in the config files.
@bluetech what if there was a generic hook for updating the config post-parsing or something like that?
P.S. Apparently, I didn't share my hacks with accessing the private config object when creating the issue. Perhaps, it's still useful to mention this: https://github.com/cherrypy/cheroot/blob/7b42482d63ffea3f562ddde0147eb275f107bc4b/cheroot/test/_pytest_plugin.py#L49-L60
How about a hook that's called to configure warnings
In code we should use python