Skip to content

Add missing __test__ check for discovery #2099

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

Merged
merged 1 commit into from
Nov 30, 2016
Merged

Add missing __test__ check for discovery #2099

merged 1 commit into from
Nov 30, 2016

Conversation

decentral1se
Copy link
Contributor

Closes #2007.

Not sure if the test is in the right place?

@@ -502,6 +502,8 @@ def _get_xunit_func(obj, name):
class Class(PyCollector):
""" Collector for test methods. """
def collect(self):
if not getattr(self.obj, "__test__", True):
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you have to return [] here.

assert True
""")
result = testdir.runpytest()
assert "cannot collect test class 'TestFoo'" not in result.stdout.str()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also ensure something about the output, I suggest this:

result.stdout.fnmatch_lines([
    'collected 0 items',
    '*no tests ran in*',
])

@@ -1,6 +1,9 @@
3.0.5.dev0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a behavior change, I think we should play safe here and merge this into features. Could you please change the target branch of the PR?

@@ -502,6 +502,8 @@ def _get_xunit_func(obj, name):
class Class(PyCollector):
""" Collector for test methods. """
def collect(self):
if not getattr(self.obj, "__test__", True):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pytest.compat has a safe_getattr which returns a default when exceptions happen - shouldn't this be used here? (see #214)

@@ -85,6 +85,19 @@ def pytest_collect_file(path, parent):
assert len(nodes) == 1
assert isinstance(nodes[0], pytest.File)

def test_can_skip_class_with_test_attr(self, testdir):
"""Assure warning is not outputted when using `__test__=True` (See #2007)"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this say "False"?

@decentral1se decentral1se changed the base branch from master to features November 30, 2016 09:14
@decentral1se
Copy link
Contributor Author

decentral1se commented Nov 30, 2016

Addressed those comments and changed the target branch 👍

Not sure I got the CHANGELOG.rst entry in the right place?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.002%) to 92.714% when pulling 6f38427 on lwm:fixup-2007 into 36eb5b3 on pytest-dev:features.

class TestFoo():
__test__ = False
def __init__(self):
return self.__init__()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while this will hopefully never be called, its still a endless recursion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, oh yeah, let's get rid of that.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.002%) to 92.714% when pulling 6f38427 on lwm:fixup-2007 into 36eb5b3 on pytest-dev:features.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.002%) to 92.714% when pulling 6530da9 on lwm:fixup-2007 into 36eb5b3 on pytest-dev:features.

@nicoddemus
Copy link
Member

Not sure I got the CHANGELOG.rst entry in the right place?

Yeah sorry for not being clearer: the features branch is the target branch for the next minor release (3.1.0). Since your PR contains a behavior change (albeit small), that's why I asked you to change your target branch to features.

So your CHANGELOG entry should be in the Changes section under the 3.1.0.dev header.

While we are at it, I think we could reword the entry a bit to convey to end-users better what was fixed, perhaps:

It is now possible to skip test classes from being collected by pytest by setting a ``__test__`` attribute to ``False`` in the class body (`#2007`_).

Other than that the rest LGTM for merging! Thanks again!

@decentral1se
Copy link
Contributor Author

Thanks for the clarification @nicoddemus. I'll get the hang of wording theseCHANGELOG.rst entries eventually ;) Squashed all my fixups 👍

@coveralls
Copy link

Coverage Status

Coverage increased (+0.002%) to 92.714% when pulling 3d1e46f on lwm:fixup-2007 into 36eb5b3 on pytest-dev:features.

@nicoddemus
Copy link
Member

LGTM, thanks @lwm for the patience!

@The-Compiler could you review the recent changes and merge if you are OK with them?

@@ -13,6 +13,10 @@ New Features
Changes
-------

* It is now possible to skip test classes from being collected by setting a
``__test__`` attribute to ``False`` in the class body (`#2007`_).* Thanks
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the * there a typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yes, fixed that one!

@@ -85,6 +85,22 @@ def pytest_collect_file(path, parent):
assert len(nodes) == 1
assert isinstance(nodes[0], pytest.File)

def test_can_skip_class_with_test_attr(self, testdir):
"""Assure warning is not outputted when using `__test__=False` (See #2007)"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed that this docstring seems to be out-dated.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.002%) to 92.714% when pulling 51faac9 on lwm:fixup-2007 into 36eb5b3 on pytest-dev:features.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.002%) to 92.714% when pulling f5afd8c on lwm:fixup-2007 into 36eb5b3 on pytest-dev:features.

@nicoddemus
Copy link
Member

nicoddemus commented Nov 30, 2016

I think it's ready to go. @The-Compiler please feel free to merge if you are also OK with it.

@The-Compiler The-Compiler merged commit 9c224c9 into pytest-dev:features Nov 30, 2016
@The-Compiler
Copy link
Member

Looks good, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants