Skip to content

Commit

Permalink
Merge pull request #47 from nicoddemus/5.4-compat
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed May 8, 2020
2 parents 407df50 + e91b797 commit 48da9c1
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 15 deletions.
12 changes: 7 additions & 5 deletions .travis.yml
Expand Up @@ -2,15 +2,17 @@ language: python

jobs:
include:
- env: TOXENV=py27
- env: TOXENV=py27-pytestlatest
python: '2.7'
- env: TOXENV=py35
- env: TOXENV=py35-pytestlatest
python: '3.5'
- env: TOXENV=py36
- env: TOXENV=py36-pytestlatest
python: '3.6'
- env: TOXENV=py37
- env: TOXENV=py37-pytestlatest
python: '3.7'
- env: TOXENV=py38
- env: TOXENV=py38-pytestlatest
python: '3.8'
- env: TOXENV=py38-pytest53
python: '3.8'
- stage: deploy
python: '3.8'
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
# 1.2.1

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

# 1.2.0

- `pytest-cpp` no longer supports Python 3.4.
Expand Down
32 changes: 26 additions & 6 deletions pytest_cpp/plugin.py
Expand Up @@ -13,6 +13,10 @@
_ARGUMENTS = 'cpp_arguments'


# pytest 5.4 introduced the 'from_parent' constructor
needs_from_parent = hasattr(pytest.Item, "from_parent")


def pytest_collect_file(parent, path):
try:
is_executable = os.stat(str(path)).st_mode & stat.S_IXUSR
Expand All @@ -38,7 +42,10 @@ def pytest_collect_file(parent, path):
return
for facade_class in FACADES:
if facade_class.is_test_suite(str(path)):
return CppFile(path, parent, facade_class(), test_args)
if needs_from_parent:
return CppFile.from_parent(fspath=path, parent=parent, facade=facade_class(), arguments=test_args)
else:
return CppFile(path, parent, facade_class(), test_args)


def pytest_addoption(parser):
Expand All @@ -57,22 +64,35 @@ def pytest_addoption(parser):


class CppFile(pytest.File):
def __init__(self, path, parent, facade, arguments):
pytest.File.__init__(self, path, parent)
def __init__(self, fspath, parent, facade, arguments):
pytest.File.__init__(self, fspath, parent)
self.facade = facade
self._arguments = arguments

@classmethod
def from_parent(cls, parent, fspath, facade, arguments):
# TODO: after dropping python 2, change to keyword only after 'parent'
return super().from_parent(parent=parent, fspath=fspath, facade=facade, arguments=arguments)

def collect(self):
for test_id in self.facade.list_tests(str(self.fspath)):
yield CppItem(test_id, self, self.facade, self._arguments)
if needs_from_parent:
yield CppItem.from_parent(parent=self, name=test_id, facade=self.facade, arguments=self._arguments)
else:
yield CppItem(test_id, self, self.facade, self._arguments)


class CppItem(pytest.Item):
def __init__(self, name, collector, facade, arguments):
pytest.Item.__init__(self, name, collector)
def __init__(self, name, parent, facade, arguments):
pytest.Item.__init__(self, name, parent)
self.facade = facade
self._arguments = arguments

@classmethod
def from_parent(cls, parent, name, facade, arguments):
# TODO: after dropping python 2, change to keyword only after 'parent'
return super().from_parent(name=name, parent=parent, facade=facade, arguments=arguments)

def runtest(self):
failures = self.facade.run_test(str(self.fspath),
self.name,
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Expand Up @@ -9,7 +9,10 @@
entry_points={
'pytest11': ['cpp = pytest_cpp.plugin'],
},
install_requires=['pytest', 'colorama'],
install_requires=[
'pytest !=5.4.0, !=5.4.1',
'colorama',
],

# metadata for upload to PyPI
author="Bruno Oliveira",
Expand Down
7 changes: 4 additions & 3 deletions tox.ini
@@ -1,12 +1,13 @@
[tox]
envlist = py{27,35,36,37,38}
envlist = py{27,35,36,37,38,38}-pytestlatest,py38-pytest53

[testenv]
deps=
pytest
pytestlatest: pytest
pytest53: pytest ~=5.3
pytest-mock
pytest-xdist
coverage
commands=
coverage run --source=pytest_cpp -m pytest tests
py.test -n8 tests
pytest -n8 tests

0 comments on commit 48da9c1

Please sign in to comment.