|
6 | 6 | import pytest |
7 | 7 |
|
8 | 8 | from pytest_cpp.boost import BoostTestFacade |
9 | | -from pytest_cpp.error import CppFailureRepr, CppFailureError |
10 | | -from pytest_cpp.google import GoogleTestFacade |
11 | 9 | from pytest_cpp.catch2 import Catch2Facade |
| 10 | +from pytest_cpp.error import CppFailureError |
| 11 | +from pytest_cpp.error import CppFailureRepr |
| 12 | +from pytest_cpp.google import GoogleTestFacade |
12 | 13 |
|
13 | 14 | FACADES = [GoogleTestFacade, BoostTestFacade, Catch2Facade] |
14 | 15 | DEFAULT_MASKS = ("test_*", "*_test") |
15 | 16 |
|
16 | 17 | _ARGUMENTS = "cpp_arguments" |
17 | 18 |
|
18 | 19 |
|
19 | | -# pytest 5.4 introduced the 'from_parent' constructor |
20 | | -needs_from_parent = hasattr(pytest.Item, "from_parent") |
21 | | - |
22 | | - |
23 | 20 | def matches_any_mask(path, masks): |
24 | 21 | """Return True if the given path matches any of the masks given""" |
25 | 22 | if sys.platform.startswith("win"): |
@@ -52,20 +49,12 @@ def pytest_collect_file(parent, file_path): |
52 | 49 |
|
53 | 50 | for facade_class in FACADES: |
54 | 51 | if facade_class.is_test_suite(str(file_path)): |
55 | | - if needs_from_parent: |
56 | | - return CppFile.from_parent( |
57 | | - path=file_path, |
58 | | - parent=parent, |
59 | | - facade=facade_class(), |
60 | | - arguments=test_args, |
61 | | - ) |
62 | | - else: |
63 | | - return CppFile( |
64 | | - path=file_path, |
65 | | - parent=parent, |
66 | | - facade_class=facade_class(), |
67 | | - arguments=test_args, |
68 | | - ) |
| 52 | + return CppFile.from_parent( |
| 53 | + path=file_path, |
| 54 | + parent=parent, |
| 55 | + facade=facade_class(), |
| 56 | + arguments=test_args, |
| 57 | + ) |
69 | 58 |
|
70 | 59 |
|
71 | 60 | def pytest_addoption(parser): |
@@ -115,15 +104,12 @@ def from_parent(cls, *, parent, path, facade, arguments, **kwargs): |
115 | 104 |
|
116 | 105 | def collect(self): |
117 | 106 | for test_id in self.facade.list_tests(str(self.fspath)): |
118 | | - if needs_from_parent: |
119 | | - yield CppItem.from_parent( |
120 | | - parent=self, |
121 | | - name=test_id, |
122 | | - facade=self.facade, |
123 | | - arguments=self._arguments, |
124 | | - ) |
125 | | - else: |
126 | | - yield CppItem(test_id, self, self.facade, self._arguments) |
| 107 | + yield CppItem.from_parent( |
| 108 | + parent=self, |
| 109 | + name=test_id, |
| 110 | + facade=self.facade, |
| 111 | + arguments=self._arguments, |
| 112 | + ) |
127 | 113 |
|
128 | 114 |
|
129 | 115 | class CppItem(pytest.Item): |
|
0 commit comments