-
-
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
No assertion rewriting in files imported from conftest #1871
Comments
pytest 3.0 removed the assertion reinterpretation which made this nice: pytest-dev/pytest#1871
You will have to call import pytest
pytest.register_assert_rewrite('testutils')
from testutils import SomeClass
@pytest.fixture
def some_obj():
return SomeClass() This now works as expected:
|
Oh - thanks, that worked beautifully (even with a package)! Do you think we should do something automatically (like I outlined above) or should I close this? I don't really have a strong opinion on it. |
This would mean that projects which decide to place tests next to the code would get their own non-test code rewritten, which is something @flub and @RonnyPfannschmidt are against (and with good reason).
Same problem as above.
That might not be safe as well because I would really love some way to automate this in some way, but I don't really have an idea for that at the moment. 😁 |
Ideally you'd do that More importantly however is that you did not find the documentation for this when you upgraded to 3.0. How can we improve that? |
Agreed, it's just that @The-Compiler's test suite doesn't have any
Good point. We have some docs here already, but maybe we should've mentioned that more prominently on the CHANGELOG, I don't know... suggestions are welcome. |
Do we have some agreed-upon recommendation whether to do that or not yet? Seems like the answer changes depending on whom I ask 😆
As Bruno pointed out, what I usually do when doing an upgrade (and certainly with a major one) is reading the changelog.
|
FWIW I think it is still valid to add that to the CHANGELOG, it might be helpful for someone else down the road. 😁 |
It helps mentioning this explicitly in the changelog. Fixes pytest-dev#1871.
I guess I can't be the only one importing some utility code from
conftest.py
, or can I? 😉With this
conftest.py
:And a
testutils.py
:And a
test_foo.py
:With pytest 2.9, I guess assertion reinterpretion kicks in and I get:
With 3.0, that's removed and I get plain asserts:
Since I have some custom assertion helpers and stuff in separated files, that's quite a bummer.
I'm not sure what the best way to fix this would be - ideas I had so far:
conftest.py
filesconftest.py
files (probably cleanest, but maybe hard to implement?)The text was updated successfully, but these errors were encountered: