-
Notifications
You must be signed in to change notification settings - Fork 29
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
Deprecations fixture #19
base: master
Are you sure you want to change the base?
Conversation
A new Deprecations fixture is added which when active causes calls to deprecated function to raise.
This is triggering warnings in travis - fixtures/tests/_fixtures/test_deprecations.py:38: DeprecationWarning: message ignored warnings.warn('message ignored', DeprecationWarning) fixtures/tests/_fixtures/test_deprecations.py:45: DeprecationWarning: message ignored warnings.warn('message ignored', DeprecationWarning) fixtures/tests/_fixtures/test_deprecations.py:59: DeprecationWarning: message ignored warnings.warn('message ignored', DeprecationWarning) fixtures/tests/_fixtures/test_deprecations.py:54: DeprecationWarning: message ignored warnings.warn('message ignored', DeprecationWarning) |
++++++++++++ | ||
|
||
Prevent code under test from calling deprecated functions. | ||
|
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.
You'll need to import warnings here.
You can make this a little cleaner by writing the test using with (we no longer support 2.5)
>>> with fixture:
... warnings.warn('stop using me', DeprecationWarning)
Exception...
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.
imported warnings and now local tox -e py27 works. Also switched to using context for the setUp/cleanUp.
unit tests fail due to the example not importing warnings.
This is a little cleaner
Hi, thanks for the patch, sorry for failing to review promptly. Please nag me on IRC in future! Have you considered making the fixture wrap catch_warnings? That would fix the resetwarnings error, though users would have to be sure to nest Deprecations usage (which testtools.TestCase.useFixture() does naturally, so that should be fine), and would prevent stdout noise making tests hard to read at the same time. Review status: 0 of 7 files reviewed at latest revision, 13 unresolved discussions. fixtures/_fixtures/deprecations.py, line 13 [r2] (raw file): fixtures/_fixtures/deprecations.py, line 14 [r2] (raw file): fixtures/_fixtures/deprecations.py, line 19 [r2] (raw file): fixtures/_fixtures/deprecations.py, line 25 [r2] (raw file): fixtures/_fixtures/deprecations.py, line 44 [r2] (raw file): fixtures/_fixtures/deprecations.py, line 45 [r2] (raw file): fixtures/_fixtures/deprecations.py, line 56 [r2] (raw file): e.g. I'd expect a test like: with Deprecations(name): to fail. fixtures/_fixtures/deprecations.py, line 63 [r2] (raw file): fixtures/_fixtures/deprecations.py, line 65 [r2] (raw file): That said, having the function here is ok, but I think we'll want to tweak the name and docstring - since nothing will fail if you call expect_deprecations() and then don't trigger any deprecations. fixtures/_fixtures/deprecations.py, line 84 [r2] (raw file): @contextlib.contextmanager Again though, the name is misleading, as there is no actual expectation - this is limited to disabling the check, not to actually providing an expectation. fixtures/tests/_fixtures/test_deprecations.py, line 14 [r2] (raw file): fixtures/tests/_fixtures/test_deprecations.py, line 59 [r2] (raw file): This is missing tests that check the interaction with global state - e.g. having two separate Deprecations fixtures at the moment won't work properly because of resetwarnings. Comments from the review on Reviewable.io |
ping |
Conflicts: fixtures/__init__.py
Review status: 0 of 7 files reviewed at latest revision, 13 unresolved discussions. fixtures/_fixtures/deprecations.py, line 13 [r2] (raw file): fixtures/_fixtures/deprecations.py, line 14 [r2] (raw file): fixtures/_fixtures/deprecations.py, line 19 [r2] (raw file): fixtures/_fixtures/deprecations.py, line 25 [r2] (raw file): fixtures/_fixtures/deprecations.py, line 44 [r2] (raw file): fixtures/_fixtures/deprecations.py, line 45 [r2] (raw file): fixtures/_fixtures/deprecations.py, line 63 [r2] (raw file): fixtures/tests/_fixtures/test_deprecations.py, line 14 [r2] (raw file): Comments from Reviewable |
Review status: 0 of 6 files reviewed at latest revision, 13 unresolved discussions. fixtures/_fixtures/deprecations.py, line 56 [r2] (raw file): fixtures/_fixtures/deprecations.py, line 65 [r2] (raw file): fixtures/_fixtures/deprecations.py, line 84 [r2] (raw file): Comments from Reviewable |
Review status: 0 of 6 files reviewed at latest revision, 13 unresolved discussions. fixtures/tests/_fixtures/test_deprecations.py, line 59 [r2] (raw file): Comments from Reviewable |
This is looking pretty close. One aesthetic thing - this is dealing with warnings, so I'd really like to see the code for it be in warnings.py (and test_warnings.py) - its sufficiently small that there is no point having a new module IMO. And the sole remaining functionality issue is getting the interactions with ignore_deprecations_here lined up. The key thing is that we have two fixtures here - Deprecations and IgnoreDeprecationsHere, both of which should nest cleanly. cleanly meaning:
Review status: 0 of 6 files reviewed at latest revision, 17 unresolved discussions. fixtures/_fixtures/deprecations.py, line 19 [r2] (raw file): fixtures/_fixtures/deprecations.py, line 44 [r2] (raw file): fixtures/_fixtures/deprecations.py, line 66 [r3] (raw file): fixtures/_fixtures/deprecations.py, line 71 [r3] (raw file): fixtures/_fixtures/deprecations.py, line 87 [r3] (raw file): fixtures/tests/_fixtures/test_deprecations.py, line 59 [r2] (raw file): fixtures/tests/_fixtures/test_deprecations.py, line 28 [r3] (raw file):
Either as a fixture itself, or in setUp to apply it to all tests. fixtures/tests/_fixtures/test_deprecations.py, line 40 [r3] (raw file): fixtures/tests/_fixtures/test_deprecations.py, line 47 [r3] (raw file): for instance:
will fail today, I believe - and its not obvious that it will. More seriously, I'm fairly sure that
will also fail: - because the cleanup called in ignore_deprecations_here() will wipe it out: and this is even less obvious. So - what I'm proposing is that ignore_deprecations_here should not exit-and-enter: it should pop and insert the single filter that matters. Comments from Reviewable |
A new Deprecations fixture is added which when active causes calls
to deprecated function to raise.