-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Integrate pytest warnings #2072
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
Integrate pytest warnings #2072
Conversation
This is useful when to use regular expressions, like for example ignore a bunch of dynamic messages --filterwarnigns 'ignore:Please use assert.* instead.:' Or ignore all the warnings in a sub-backage --filterwarnigns 'ignore:::package.submodule.*' This is also available in the ini file as the filterwarnigns options
Add a warning option which does not escape its arguments.
|
|
Btw there are failing tests because now there are more "pytest-warnings" being displayed, for various reasons. Would like to nail down the discussion before fixing those. |
Gentle pinging @fschulze, @RonnyPfannschmidt, @hpk42, @The-Compiler and @flub Would like to get the discussion going. 😁 |
No one does anything about stuff if it's ignored, so I would vote against ignoring by default. It's better to add info how to hide warnings. Especially selectively like for modules you don't care about or specific types of warnings. A pointer to docs when there are more then 5 warnings perhaps.
I agree that we should capture setup/teardown as well. The original plan was to also replace the calls to Currently warnings aren't transferred when using xdist, that's a major blocker IMO and I've got no clue what is involved to fix that. |
Thanks @fschulze, I will evolve the implementation a bit based on your feedback! |
FIxed the issue with WarningsRecorder calls the original Calling the original warnings.showwarnings has the effect that nested WarningsRecorder all catch the warnings: with WarningsRecorder() as rec1:
with WarningsRecorder() as rec2:
warnings.warn(UserWarning, 'some warning') (both When running tests with I'm considering removing |
This has the benefical side-effect of not calling the original warnings.showwarnings function, which in its original form only writes the formatted warning to sys.stdout. Calling the original warnings.showwarnings has the effect that nested WarningsRecorder all catch the warnings: with WarningsRecorder() as rec1: with WarningsRecorder() as rec2: warnings.warn(UserWarning, 'some warning') (both rec1 and rec2 sees the warning) When running tests with `testdir`, the main pytest session would then see the warnings created by the internal code being tested (if any), and the main pytest session would end up with warnings as well.
The rationale of using node ids is that users can copy/paste it to run a chosen test
I think this is now ready for review! 😅 |
The CI seems to disagree 😉 |
# produced by path.local | ||
ignore:bad escape.*:DeprecationWarning:re | ||
# produced by path.readlines | ||
ignore:.*U.*mode is deprecated:DeprecationWarning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those should probably be fixed in pylib
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pytest-dev/py#116 is there to fix this
- pytester was creating a 'pexpect' directory to serve as temporary dir, but due to the fact that xdist adds the current directory to sys.path, that directory was being considered as candidate for import as a package. The directory is empty and a warning was being raised about it missing __init__ file, which is now turned into an error by our filterwarnings config in pytest.ini. - Decided to play it safe and ignore any warnings during `pytest.importorskip`. - pytest-xdist and execnet raise two warnings which should be fixed upstream: pytest-dev/pytest-xdist/issues/133
For some reason pypy raises this warning in the line that the catch_warnings block was added: ______________________________ ERROR collecting ______________________________ C:\ProgramData\chocolatey\lib\python.pypy\tools\pypy2-v5.4.1-win32\lib-python\2.7\pkgutil.py:476: in find_loader loader = importer.find_module(fullname) c:\pytest\.tox\pypy\site-packages\_pytest\assertion\rewrite.py:75: in find_module fd, fn, desc = imp.find_module(lastname, path) <builtin>/?:3: in anonymous ??? E ImportWarning: Not importing directory 'c:\users\bruno\appdata\local\temp\pytest-of-Bruno\pytest-3192\testdir\test_cmdline_python_package0' missing __init__.py
Summary of the problems that lead to CI failing in some environments:
Turning warnings into errors is fun. 😎 |
@@ -1008,7 +1008,7 @@ def spawn_pytest(self, string, expect_timeout=10.0): | |||
The pexpect child is returned. | |||
|
|||
""" | |||
basetemp = self.tmpdir.mkdir("pexpect") | |||
basetemp = self.tmpdir.mkdir("temp-pexpect") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that must have been so puzzleing
looks good to me, unless someone notices something i missed, i'll merge this afternoon, great dob 👍 |
@nicoddemus that bit again ^^ , thanks, i'll merge after its green |
Heh just noticed it this morning, but was busy so only now managed to get to it. 😁 |
Will this work correctly with |
This PR starts the work to integrate fschulze/pytest-warnings.
I managed to preserve history and authorship, and the integration itself was smooth.
It is working as can be seen here:
Some points I would like to discuss before moving this further:
pytest-warnings
back to just warnings, since it now it displays system warnings as well as pytest's own warnings.test_warnings.py:14:
should include the name of the function as well IMHO (test_warnings.py:test_foo:14:
).-W error
switch so future warnings break immediately.3.1.0
because I'm sure it will spew a ton of warnings. Then users can enable this gradatively and select which warnings they want to handle.testdir
which raise warnings, the warnings are also displayed in the "main" session. I made a quick experiment to fix this by deleting the warnings after they were printed by the terminal reporter, but that didn't work. I will have to investigate more.Would love to hear your feedback.