File tree Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Original file line number Diff line number Diff line change 1+ Deselected items from plugins using ``pytest_collect_modifyitems `` as a hookwrapper are correctly reported now.
Original file line number Diff line number Diff line change @@ -552,10 +552,6 @@ def report_collect(self, final=False):
552552 else :
553553 self .write_line (line )
554554
555- @pytest .hookimpl (trylast = True )
556- def pytest_collection_modifyitems (self ):
557- self .report_collect (True )
558-
559555 @pytest .hookimpl (trylast = True )
560556 def pytest_sessionstart (self , session ):
561557 self ._session = session
@@ -608,6 +604,8 @@ def pytest_report_header(self, config):
608604 return result
609605
610606 def pytest_collection_finish (self , session ):
607+ self .report_collect (True )
608+
611609 if self .config .getoption ("collectonly" ):
612610 self ._printcollecteditems (session .items )
613611
Original file line number Diff line number Diff line change @@ -506,6 +506,37 @@ def test_three():
506506 )
507507 assert result .ret == 0
508508
509+ def test_deselected_with_hookwrapper (self , testdir ):
510+ testpath = testdir .makeconftest (
511+ """
512+ import pytest
513+
514+ @pytest.hookimpl(hookwrapper=True)
515+ def pytest_collection_modifyitems(config, items):
516+ yield
517+ deselected = items.pop()
518+ config.hook.pytest_deselected(items=[deselected])
519+ """
520+ )
521+ testpath = testdir .makepyfile (
522+ """
523+ def test_one():
524+ pass
525+ def test_two():
526+ pass
527+ def test_three():
528+ pass
529+ """
530+ )
531+ result = testdir .runpytest (testpath )
532+ result .stdout .fnmatch_lines (
533+ [
534+ "collected 3 items / 1 deselected / 2 selected" ,
535+ "*= 2 passed, 1 deselected in*" ,
536+ ]
537+ )
538+ assert result .ret == 0
539+
509540 def test_show_deselected_items_using_markexpr_before_test_execution (self , testdir ):
510541 testdir .makepyfile (
511542 test_show_deselected = """
You can’t perform that action at this time.
0 commit comments