Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# 1.2.1

- Remove `from_parent()` warnings in pytest 5.4.2+.
- Remove `from_parent()`-related warnings in pytest 5.4.2+.

- Masks like `*_test` now work correctly on Windows by automatically appending the
expected `".exe"` suffix (#45).
Thanks @1fabrism for the report.

# 1.2.0

Expand Down
17 changes: 11 additions & 6 deletions pytest_cpp/plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import stat
import sys

import pytest

Expand All @@ -16,6 +17,12 @@
# pytest 5.4 introduced the 'from_parent' constructor
needs_from_parent = hasattr(pytest.Item, "from_parent")

def matches_any_mask(path, masks):
"""Return True if the given path matches any of the masks given"""
if sys.platform.startswith("win"):
masks = [m + ".exe" for m in masks]
return any(path.fnmatch(m) for m in masks)


def pytest_collect_file(parent, path):
try:
Expand All @@ -34,12 +41,10 @@ def pytest_collect_file(parent, path):
# don't attempt to check *.py files even if they were given as explicit arguments
if cpp_ignore_py_files and path.fnmatch('*.py'):
return
if not parent.session.isinitpath(path):
for pat in masks:
if path.fnmatch(pat):
break
else:
return

if not parent.session.isinitpath(path) and not matches_any_mask(path, masks):
return

for facade_class in FACADES:
if facade_class.is_test_suite(str(path)):
if needs_from_parent:
Expand Down
17 changes: 17 additions & 0 deletions tests/test_pytest_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,23 @@ def test_race_condition_on_collect(tmpdir):
assert pytest_cpp.plugin.pytest_collect_file(None, tmpdir / 'invalid-file') is None


def test_exe_mask_on_windows(tmpdir, monkeypatch):
"""
Test for #45: C++ tests not collected due to '*_test' mask on Windows
"""
import pytest_cpp.plugin
monkeypatch.setattr(sys, "platform", "win32")

fn = tmpdir.join("generator_demo_test.exe").ensure(file=1)
assert pytest_cpp.plugin.matches_any_mask(fn, ["test_*", "*_test"])

fn = tmpdir.join("test_generator_demo.exe").ensure(file=1)
assert pytest_cpp.plugin.matches_any_mask(fn, ["test_*", "*_test"])

fn = tmpdir.join("my_generator_test_demo.exe").ensure(file=1)
assert not pytest_cpp.plugin.matches_any_mask(fn, ["test_*", "*_test"])


class TestError:

def test_get_whitespace(self):
Expand Down