Skip to content

Commit 48da9c1

Browse files
authored
Merge pull request #47 from nicoddemus/5.4-compat
2 parents 407df50 + e91b797 commit 48da9c1

File tree

5 files changed

+45
-15
lines changed

5 files changed

+45
-15
lines changed

.travis.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ language: python
22

33
jobs:
44
include:
5-
- env: TOXENV=py27
5+
- env: TOXENV=py27-pytestlatest
66
python: '2.7'
7-
- env: TOXENV=py35
7+
- env: TOXENV=py35-pytestlatest
88
python: '3.5'
9-
- env: TOXENV=py36
9+
- env: TOXENV=py36-pytestlatest
1010
python: '3.6'
11-
- env: TOXENV=py37
11+
- env: TOXENV=py37-pytestlatest
1212
python: '3.7'
13-
- env: TOXENV=py38
13+
- env: TOXENV=py38-pytestlatest
14+
python: '3.8'
15+
- env: TOXENV=py38-pytest53
1416
python: '3.8'
1517
- stage: deploy
1618
python: '3.8'

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.2.1
2+
3+
- Remove `from_parent()` warnings in pytest 5.4.2+.
4+
15
# 1.2.0
26

37
- `pytest-cpp` no longer supports Python 3.4.

pytest_cpp/plugin.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
_ARGUMENTS = 'cpp_arguments'
1414

1515

16+
# pytest 5.4 introduced the 'from_parent' constructor
17+
needs_from_parent = hasattr(pytest.Item, "from_parent")
18+
19+
1620
def pytest_collect_file(parent, path):
1721
try:
1822
is_executable = os.stat(str(path)).st_mode & stat.S_IXUSR
@@ -38,7 +42,10 @@ def pytest_collect_file(parent, path):
3842
return
3943
for facade_class in FACADES:
4044
if facade_class.is_test_suite(str(path)):
41-
return CppFile(path, parent, facade_class(), test_args)
45+
if needs_from_parent:
46+
return CppFile.from_parent(fspath=path, parent=parent, facade=facade_class(), arguments=test_args)
47+
else:
48+
return CppFile(path, parent, facade_class(), test_args)
4249

4350

4451
def pytest_addoption(parser):
@@ -57,22 +64,35 @@ def pytest_addoption(parser):
5764

5865

5966
class CppFile(pytest.File):
60-
def __init__(self, path, parent, facade, arguments):
61-
pytest.File.__init__(self, path, parent)
67+
def __init__(self, fspath, parent, facade, arguments):
68+
pytest.File.__init__(self, fspath, parent)
6269
self.facade = facade
6370
self._arguments = arguments
6471

72+
@classmethod
73+
def from_parent(cls, parent, fspath, facade, arguments):
74+
# TODO: after dropping python 2, change to keyword only after 'parent'
75+
return super().from_parent(parent=parent, fspath=fspath, facade=facade, arguments=arguments)
76+
6577
def collect(self):
6678
for test_id in self.facade.list_tests(str(self.fspath)):
67-
yield CppItem(test_id, self, self.facade, self._arguments)
79+
if needs_from_parent:
80+
yield CppItem.from_parent(parent=self, name=test_id, facade=self.facade, arguments=self._arguments)
81+
else:
82+
yield CppItem(test_id, self, self.facade, self._arguments)
6883

6984

7085
class CppItem(pytest.Item):
71-
def __init__(self, name, collector, facade, arguments):
72-
pytest.Item.__init__(self, name, collector)
86+
def __init__(self, name, parent, facade, arguments):
87+
pytest.Item.__init__(self, name, parent)
7388
self.facade = facade
7489
self._arguments = arguments
7590

91+
@classmethod
92+
def from_parent(cls, parent, name, facade, arguments):
93+
# TODO: after dropping python 2, change to keyword only after 'parent'
94+
return super().from_parent(name=name, parent=parent, facade=facade, arguments=arguments)
95+
7696
def runtest(self):
7797
failures = self.facade.run_test(str(self.fspath),
7898
self.name,

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
entry_points={
1010
'pytest11': ['cpp = pytest_cpp.plugin'],
1111
},
12-
install_requires=['pytest', 'colorama'],
12+
install_requires=[
13+
'pytest !=5.4.0, !=5.4.1',
14+
'colorama',
15+
],
1316

1417
# metadata for upload to PyPI
1518
author="Bruno Oliveira",

tox.ini

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
[tox]
2-
envlist = py{27,35,36,37,38}
2+
envlist = py{27,35,36,37,38,38}-pytestlatest,py38-pytest53
33

44
[testenv]
55
deps=
6-
pytest
6+
pytestlatest: pytest
7+
pytest53: pytest ~=5.3
78
pytest-mock
89
pytest-xdist
910
coverage
1011
commands=
1112
coverage run --source=pytest_cpp -m pytest tests
12-
py.test -n8 tests
13+
pytest -n8 tests

0 commit comments

Comments
 (0)