-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Issue #562 - Ensure @nose.tools.istest is respected #921
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
Issue #562 - Ensure @nose.tools.istest is respected #921
Conversation
@@ -335,6 +337,9 @@ class PyCollector(PyobjMixin, pytest.Collector): | |||
def funcnamefilter(self, name): | |||
return self._matches_prefix_or_glob_option('python_functions', name) | |||
|
|||
def isnosetestfunction(self, obj): | |||
return getattr(obj, '__test__', False) |
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.
test_parsefactories_evil_objects_issue214
is failing, which shows that in order to be safe during collection (#214), this would be safer:
def isnosetestfunction(self, obj):
try:
return obj.__test__
except Exception:
return False
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.
Why not except Exception:
to avoid catching KeyboardInterrupt
and the like?
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.
Argh, brain fart, you're right of course. Thanks! (updated my example)
Thanks for the PR @tomviner! 😄 Besides the comment I made regarding the failing test, the patch looks good to me! Could you also please add yourself to |
@@ -248,8 +248,10 @@ def pytest_pycollect_makeitem(collector, name, obj): | |||
if collector.classnamefilter(name): | |||
Class = collector._getcustomclass("Class") | |||
outcome.force_result(Class(name, parent=collector)) | |||
elif collector.funcnamefilter(name) and hasattr(obj, "__call__") and\ | |||
getfixturemarker(obj) is None: | |||
elif ( |
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 condition is starting to be waaay to complex, can you turn it into a method?
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.
👍
5210838
to
b3e9df5
Compare
This patch is now made up of:
I'd have liked to have made these changes solely in nose.py (rather than python.py), does anyone think that would have been possible? So we now match the nose functionality of allowing functions and classes (but not modules) to be selected regardless of name with the Here's a final test on the command line, using these 3 test files: ==> check.py <==
# regardless of this, the filename mismatch precludes this having any effect
__test__ = True
def test_me__not_run():
pass
==> test_false.py <==
# nothing gets run in this module
__test__ = False
def test_me__not_run():
pass
==> test_things.py <==
import nose.tools
# will not get run
@nose.tools.nottest
def test_stuff__not_run():
pass
@nose.tools.nottest
class TestPrefix():
def test_stuff__not_run(self):
pass
# will run
@nose.tools.istest
class AnyName:
def test_stuff_method__will_run(self):
pass
@nose.tools.istest
def stuff__will_run():
pass With nose (nosetests version 1.3.7), 2 tests run: $ nosetests -v
test_things.AnyName.test_stuff_method__will_run ... ok
test_things.stuff__will_run ... ok With latest py.test: $ py.test -v
=== test session starts ===
platform linux2 -- Python 2.7.9 -- py-1.4.30 -- pytest-2.7.2 -- /home/tom/.virtualenvs/pytest-lib/bin/python
collected 0 items With py.test of this branch: $ py.test -v
=== test session starts ===
platform linux2 -- Python 2.7.9, pytest-2.8.0.dev4, py-1.4.30, pluggy-0.3.0 -- /home/tom/.virtualenvs/pytest/bin/python
collected 2 items
test_things.py::AnyName::test_stuff_method__will_run PASSED
test_things.py::stuff__will_run PASSED |
e841e73
to
df44333
Compare
Rebased. |
def istestfunction(self, obj, name): | ||
return ( | ||
(self.funcnamefilter(name) or self.isnosetest(obj)) | ||
and hasattr(obj, "__call__") and getfixturemarker(obj) is None |
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.
the __call__
attribute should be checked with safe_getattr
as wel
overall nicely done, great job :) |
9b2639c
to
a5c3c07
Compare
cheers, and changed that to |
Small flakes failure, could you please fix it? 😄 After this passes this is good to merge from my POV. |
Ah yes. Currently out flying drone, will fix upon return. |
a5c3c07
to
66d20a9
Compare
54bb63d
to
ad4dee3
Compare
ad4dee3
to
1462590
Compare
Flakes deflaked, couple docstrings clarified/detypoed too. All good? |
Issue #562 - Ensure @nose.tools.istest is respected
Fix for #562