From ece12a263dabd8ccda002c5499b2d8f4abb17b62 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Fri, 1 May 2020 10:05:36 -0300 Subject: [PATCH 1/2] Use from_parent() constructor from pytest 5.4 --- .travis.yml | 12 +++++++----- CHANGELOG.md | 4 ++++ pytest_cpp/plugin.py | 32 ++++++++++++++++++++++++++------ tox.ini | 7 ++++--- 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0d87825..38a86f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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' diff --git a/CHANGELOG.md b/CHANGELOG.md index a2c5680..0193803 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.2.1 + +- Remove `from_parent()` warnings in pytest 5.4+. + # 1.2.0 - `pytest-cpp` no longer supports Python 3.4. diff --git a/pytest_cpp/plugin.py b/pytest_cpp/plugin.py index 373bf60..aabf50c 100644 --- a/pytest_cpp/plugin.py +++ b/pytest_cpp/plugin.py @@ -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 @@ -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): @@ -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, diff --git a/tox.ini b/tox.ini index ed83ca9..b1fb3e1 100644 --- a/tox.ini +++ b/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 From e91b797e4adc95171a9805e7b884a980686b6952 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Fri, 1 May 2020 10:39:48 -0300 Subject: [PATCH 2/2] Require pytest 5.4.2+ on pytest 5.4 series Due to fixes in File.from_parent --- CHANGELOG.md | 2 +- setup.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0193803..96ed565 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # 1.2.1 -- Remove `from_parent()` warnings in pytest 5.4+. +- Remove `from_parent()` warnings in pytest 5.4.2+. # 1.2.0 diff --git a/setup.py b/setup.py index ba7d87c..e768475 100644 --- a/setup.py +++ b/setup.py @@ -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",