-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Small cleanups on _pytest.compat #5451
Small cleanups on _pytest.compat #5451
Conversation
Small improvements and cleanups
Codecov Report
@@ Coverage Diff @@
## master #5451 +/- ##
==========================================
+ Coverage 95.92% 96.01% +0.09%
==========================================
Files 114 114
Lines 25498 25483 -15
Branches 2479 2478 -1
==========================================
+ Hits 24458 24468 +10
+ Misses 728 709 -19
+ Partials 312 306 -6
Continue to review full report at Codecov.
|
5b4dd63
to
d8fa434
Compare
@@ -304,8 +305,8 @@ def _setup_collect_fakemodule(): | |||
|
|||
pytest.collect = ModuleType("pytest.collect") | |||
pytest.collect.__all__ = [] # used for setns | |||
for attr in COLLECT_FAKEMODULE_ATTRIBUTES: | |||
setattr(pytest.collect, attr, getattr(pytest, attr)) | |||
for attr_name in COLLECT_FAKEMODULE_ATTRIBUTES: |
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.
can we remove that in pytest 5?
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.
#5180 lists deprecations to remove in 5.1 (the deprecations will be errors in 5.0, removed in 5.1 as we did in 4.0/4.1).
Unfortunately it doesn't seem the pytest.collect
has been deprecated at all, so unless I'm mistaken our only option is to deprecate it in 5.X
and remove in 6.X
I'm afraid. 😕
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.
Not sure how to implement this deprecation thought without using a __getattr__
at module level, but that's 3.7+ only.
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.
class MyModule(ModuleType):
def __getattr__(...):
...
sys.modules[...] = ...
would work (it's essentially what py37 does)
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.
Yeah I had the exact same thought right after I posted my comment, but got side-tracked by #5452. 😛
@@ -970,7 +964,7 @@ class FixtureFunctionMarker: | |||
name = attr.ib(default=None) | |||
|
|||
def __call__(self, function): | |||
if isclass(function): | |||
if inspect.isclass(function): |
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.
wouldnt isinstance(..., type)
do as we are python3 only now
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.
|
||
@contextmanager | ||
def nullcontext(): | ||
yield |
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.
coudl even do from contextlib import ExitStack as nullcontext
@@ -304,8 +305,8 @@ def _setup_collect_fakemodule(): | |||
|
|||
pytest.collect = ModuleType("pytest.collect") | |||
pytest.collect.__all__ = [] # used for setns | |||
for attr in COLLECT_FAKEMODULE_ATTRIBUTES: | |||
setattr(pytest.collect, attr, getattr(pytest, attr)) | |||
for attr_name in COLLECT_FAKEMODULE_ATTRIBUTES: |
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.
class MyModule(ModuleType):
def __getattr__(...):
...
sys.modules[...] = ...
would work (it's essentially what py37 does)
Small improvements and cleanups