File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# 1.2.1
22
3- - Remove ` from_parent() ` warnings in pytest 5.4.2+.
3+ - Remove ` from_parent() ` -related warnings in pytest 5.4.2+.
4+
5+ - Masks like ` *_test ` now work correctly on Windows by automatically appending the
6+ expected ` ".exe" ` suffix (#45 ).
7+ Thanks @1fabrism for the report.
48
59# 1.2.0
610
Original file line number Diff line number Diff line change 11import os
22import stat
3+ import sys
34
45import pytest
56
1617# pytest 5.4 introduced the 'from_parent' constructor
1718needs_from_parent = hasattr (pytest .Item , "from_parent" )
1819
20+ def matches_any_mask (path , masks ):
21+ """Return True if the given path matches any of the masks given"""
22+ if sys .platform .startswith ("win" ):
23+ masks = [m + ".exe" for m in masks ]
24+ return any (path .fnmatch (m ) for m in masks )
25+
1926
2027def pytest_collect_file (parent , path ):
2128 try :
@@ -34,12 +41,10 @@ def pytest_collect_file(parent, path):
3441 # don't attempt to check *.py files even if they were given as explicit arguments
3542 if cpp_ignore_py_files and path .fnmatch ('*.py' ):
3643 return
37- if not parent .session .isinitpath (path ):
38- for pat in masks :
39- if path .fnmatch (pat ):
40- break
41- else :
42- return
44+
45+ if not parent .session .isinitpath (path ) and not matches_any_mask (path , masks ):
46+ return
47+
4348 for facade_class in FACADES :
4449 if facade_class .is_test_suite (str (path )):
4550 if needs_from_parent :
Original file line number Diff line number Diff line change @@ -400,6 +400,23 @@ def test_race_condition_on_collect(tmpdir):
400400 assert pytest_cpp .plugin .pytest_collect_file (None , tmpdir / 'invalid-file' ) is None
401401
402402
403+ def test_exe_mask_on_windows (tmpdir , monkeypatch ):
404+ """
405+ Test for #45: C++ tests not collected due to '*_test' mask on Windows
406+ """
407+ import pytest_cpp .plugin
408+ monkeypatch .setattr (sys , "platform" , "win32" )
409+
410+ fn = tmpdir .join ("generator_demo_test.exe" ).ensure (file = 1 )
411+ assert pytest_cpp .plugin .matches_any_mask (fn , ["test_*" , "*_test" ])
412+
413+ fn = tmpdir .join ("test_generator_demo.exe" ).ensure (file = 1 )
414+ assert pytest_cpp .plugin .matches_any_mask (fn , ["test_*" , "*_test" ])
415+
416+ fn = tmpdir .join ("my_generator_test_demo.exe" ).ensure (file = 1 )
417+ assert not pytest_cpp .plugin .matches_any_mask (fn , ["test_*" , "*_test" ])
418+
419+
403420class TestError :
404421
405422 def test_get_whitespace (self ):
You can’t perform that action at this time.
0 commit comments