-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
PYTEST_DONT_REWRITE is not checked for plugins #2995
Comments
Actually pytest already checks for that 😉 Lines 1045 to 1060 in 964c29c
|
the demo code explicitly imports the plugin before assertion rewriting, the warning is about not even trying (i.e. before we even check the docstring) pytest/_pytest/assertion/rewrite.py Line 603 in 5c6d773
so the real issue here is that op triggers a warning that in that particular case could be left out since we wouldn't rewrite to begin with |
i propose we ensure the warning triggers only for modules that dont have a dont rewrite tag pytest/_pytest/assertion/rewrite.py Lines 189 to 192 in 5c6d773
@anntzer please verify if my hypothesis is correct |
IIUC, the |
@nicoddemus thing is, the already imported module is marked as dont rewrite - so i beleive its fine to firego thatr warning in that case - in any case it wouldn't happen if the unneeded import was either left out, or the plug in was passed as plugin object to main |
Ahh true, thanks for the clarification |
I think something like the following patch should suffice:
However I would appreciate help as to how to test this feature (do you have any helper for generating a fake module going into sys.modules, for example?). Or feel free to just take over the patch yourself, either way works. |
@anntzer thanks for posting the patch. I'm short on time right now so we would appreciate a PR if you have the time Here's an example of test which uses the pytest/testing/test_assertion.py Lines 132 to 148 in 5c6d773
You can use this test as basis, I believe if you add a docstring to the result = testdir.runpytest_subprocess('--assert=rewrite')
assert 'Module already imported so can not be re-written: ham' not in result.stdout.str() The test should fail without your patch and pass with it applied. Let us know if you need further guidance. 👍 |
Enforces pytools 3.3.2 now, as older version do not support module level PYTEST_DONT_REWRITE (pytest-dev/pytest#2995).
Adding PYTEST_DONT_REWRITE to the docstring of a test module suppresses assertion rewrites; however, this does not work for plugins.
Minimal (contrieved) example:
plugin.py
run:
Python 3.6 on Arch Linux.
Alternatively, it may also be nice if the warning was only output if there actually is at least one assert in the unrewritable module (or if -O is on which may make that impossible to check, perhaps).
The text was updated successfully, but these errors were encountered: