-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Asserting repeated warning does not work in Python 2.7 #2917
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
Comments
It seems a workaround is to add |
That looks expected to me - that's just how warnings work in Python by default 😉 |
Can you point me to some part of the documentation that would explain that behaviour? The default warning filter section for 3.6 and 2.7 only talk about ignored warnings (that are not |
Also, the aforementioned workaround does not reliably work in conjunction with pytest-xdist. (But I cannot manage to produce a test case, it seems to only fail on Travis-CI.) |
I can't explain this off-hand I'm afraid. |
We're running into this as well in the marshmallow test suite. Here's a failed build on travis: https://travis-ci.org/marshmallow-code/marshmallow/builds/324608482 The test in question looks like this: def test_strict_is_deprecated():
with pytest.warns(DeprecationWarning):
class StrictUserSchema(Schema):
name = fields.String()
class Meta:
strict = False
class UserSchema(Schema):
name = fields.String()
with pytest.warns(DeprecationWarning):
UserSchema(strict=True) The problem only exists in 2.7--the test passes fine in Python 3. |
Update: The test still fails when using def test_strict_is_deprecated():
with pytest.deprecated_call():
class StrictUserSchema(Schema):
name = fields.String()
class Meta:
strict = False
class UserSchema(Schema):
name = fields.String()
with pytest.deprecated_call():
UserSchema(strict=True) |
I would suggest to change the code to use |
This problem also occurs for non-deprecation warnings. Maybe |
good news, looks like #4104 will fix this :) |
via #4104 |
Running the following test code with Python 2.7 will fail because for some reason the warning is not emitted a second time:
The output:
Running with Python 3.6.1 succeeds:
Note that this also occurs across different tests, e.g. when parametrizing:
When running tests with
pytest-xdist
in non-deterministic order this can cause random test failures with Python 2.7.The text was updated successfully, but these errors were encountered: