terminal: use pytest_collection_finish for reporting (#5113)

terminal: use pytest_collection_finish for reporting
This commit is contained in:
Bruno Oliveira 2019-04-29 08:00:48 -03:00 committed by GitHub
commit fb6dad60a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 4 deletions

View File

@ -0,0 +1 @@
Deselected items from plugins using ``pytest_collect_modifyitems`` as a hookwrapper are correctly reported now.

View File

@ -552,10 +552,6 @@ class TerminalReporter(object):
else:
self.write_line(line)
@pytest.hookimpl(trylast=True)
def pytest_collection_modifyitems(self):
self.report_collect(True)
@pytest.hookimpl(trylast=True)
def pytest_sessionstart(self, session):
self._session = session
@ -608,6 +604,8 @@ class TerminalReporter(object):
return result
def pytest_collection_finish(self, session):
self.report_collect(True)
if self.config.getoption("collectonly"):
self._printcollecteditems(session.items)

View File

@ -506,6 +506,37 @@ class TestTerminalFunctional(object):
)
assert result.ret == 0
def test_deselected_with_hookwrapper(self, testdir):
testpath = testdir.makeconftest(
"""
import pytest
@pytest.hookimpl(hookwrapper=True)
def pytest_collection_modifyitems(config, items):
yield
deselected = items.pop()
config.hook.pytest_deselected(items=[deselected])
"""
)
testpath = testdir.makepyfile(
"""
def test_one():
pass
def test_two():
pass
def test_three():
pass
"""
)
result = testdir.runpytest(testpath)
result.stdout.fnmatch_lines(
[
"collected 3 items / 1 deselected / 2 selected",
"*= 2 passed, 1 deselected in*",
]
)
assert result.ret == 0
def test_show_deselected_items_using_markexpr_before_test_execution(self, testdir):
testdir.makepyfile(
test_show_deselected="""