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
Allow downstream to disable deprecations-as-errors with environment var #989
Conversation
tests/common/setup.py
Outdated
warnings.filterwarnings('error', category=HypothesisDeprecationWarning) | ||
# We further enable deprecations as errors for all dependencies, | ||
# unless disabled for Django 1.8, or by downstream (see issue #969) | ||
disable_werror = os.environ.get('HYPOTHESIS_TESTS_NO_WERROR') == 'true' |
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.
Two questions:
- Shouldn't we document this?
- Should we provide pytest cli option to control this?
- Should we check env variable value our just ensure that this variable is set? For instance, standard Python env variables works in this way, so there is no difference between PYTHONOPTIMIZE=1 and PYTHONOPTIMIZE=true and PYTHONOPTIMIZE=yes-please.
UPD. sorry, nvm, that's internal change.
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’s three questions. 😉
I’d prefer a pytest CLI option – particularly because tox doesn’t pass through environment variables by default, so at minimum this needs a change to tox.ini
or I’m pretty sure won’t work. A CLI option is more explicit in that regard.
(Also I just generally dislike environment variables as a way to control behaviour, because they’re easy to set and forget, and then you have behaviour that seems to work by magic.)
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.
Eh, I was hope I'll fix my misunderstood before anyone noticed (: Restored comment.
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.
Hey, I liked your questions!
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.
Get all back, no worries (: And sorry for confussion /:
I'd be delighted if someone could show me how to add an argument via pytest - when I tried this it didn't work at all. I'd document this in the notes added by #988, and will do that once either pull is merged. I like explicitly checking the value of the var to avoid surprises if it's set to eg "0" or "false" - but I've added a warning for that case. |
@Zac-HD diff --git a/src/hypothesis/extra/pytestplugin.py b/src/hypothesis/extra/pytestplugin.py
index 86f01d13..60c1eed2 100644
--- a/src/hypothesis/extra/pytestplugin.py
+++ b/src/hypothesis/extra/pytestplugin.py
@@ -17,6 +17,8 @@
from __future__ import division, print_function, absolute_import
+import warnings
+
import pytest
import hypothesis.core as core
@@ -29,6 +31,7 @@ from hypothesis.internal.detection import is_hypothesis_test
LOAD_PROFILE_OPTION = '--hypothesis-profile'
PRINT_STATISTICS_OPTION = '--hypothesis-show-statistics'
SEED_OPTION = '--hypothesis-seed'
+TEST_NO_WERROR = '--hypothesis-test-no-werror'
class StoringReporter(object):
@@ -63,6 +66,12 @@ def pytest_addoption(parser):
action='store',
help='Set a seed to use for all Hypothesis tests'
)
+ group.addoption(
+ TEST_NO_WERROR,
+ action='store_true',
+ help='Stop count warnings as errors',
+ default=False
+ )
def pytest_configure(config):
@@ -81,6 +90,8 @@ def pytest_configure(config):
config.addinivalue_line(
'markers',
'hypothesis: Tests which use hypothesis.')
+ if not config.getoption(TEST_NO_WERROR):
+ warnings.filterwarnings('error', category=DeprecationWarning)
gathered_statistics = OrderedDict() |
However, may be in this case would better to have WError enable flag rather then disable. I'm not sure if condition is correct and wouldn't be overriden later by someone else. |
And again...if this switch is only for Hypothesis tests and doesn't affects users, it may be not wise to have it on public since it causes no effect for them (or at least it supposed to in original implementation - mine patch makes it global, eventually). |
I feel like this might make more sense inverted? i.e. we don't turn warnings on unless an environment variable is set. This feature is mostly useful for our testing, and downstream packagers are almost guaranteed to want to disable it, so why not make it do the right thing by default for them? I think if you do that, adding a pytest command line option is probably not that useful - if this is just for our testing and not for others' consumption, the option that involves the least amount of code is fine. :-) |
...we should probably just set |
5aecf3c
to
35b6009
Compare
So we're ready to go! In summary: if you set the standard |
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.
🎉 thanks for doing the leg work on this!
No problem - I always learn something from the little fixes, and the tooling around Hypothesis is good enough that I never feel like my time is wasted 😄 |
Works great here, thanks a lot :D |
Closes #969 - the Arch package has unbundled some upstream dependencies, so this option will be useful for @felixonmars 😄
CC @DRMacIver in case this is one of those things where we have divergent taste in solutions.