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 @@ -553,10 +553,6 @@ def report_collect(self, final=False):
553
553
else :
554
554
self .write_line (line )
555
555
556
- @pytest .hookimpl (trylast = True )
557
- def pytest_collection_modifyitems (self ):
558
- self .report_collect (True )
559
-
560
556
@pytest .hookimpl (trylast = True )
561
557
def pytest_sessionstart (self , session ):
562
558
self ._session = session
@@ -609,6 +605,8 @@ def pytest_report_header(self, config):
609
605
return result
610
606
611
607
def pytest_collection_finish (self , session ):
608
+ self .report_collect (True )
609
+
612
610
if self .config .getoption ("collectonly" ):
613
611
self ._printcollecteditems (session .items )
614
612
Original file line number Diff line number Diff line change @@ -506,6 +506,37 @@ def test_three():
506
506
)
507
507
assert result .ret == 0
508
508
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
+
509
540
def test_show_deselected_items_using_markexpr_before_test_execution (self , testdir ):
510
541
testdir .makepyfile (
511
542
test_show_deselected = """
You can’t perform that action at this time.
0 commit comments