From 4c8f6e898f889eaf3fc255e7b5998641a297208d Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 20 May 2020 17:27:44 -0300 Subject: [PATCH] Fix pytest 5.4 support --- .github/workflows/main.yml | 10 ++++++++++ CHANGELOG.rst | 5 +++++ pytest_subtests.py | 8 +++++++- tox.ini | 4 +++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6117595..e41cfda 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,11 +15,13 @@ jobs: "windows-py36", "windows-py37", "windows-py38", + "windows-py38-pytest53", "ubuntu-py35", "ubuntu-py36", "ubuntu-py37", "ubuntu-py38", + "ubuntu-py38-pytest53", "linting", ] @@ -41,6 +43,10 @@ jobs: python: "3.8" os: windows-latest tox_env: "py38" + - name: "windows-py38-pytest53" + python: "3.8" + os: windows-latest + tox_env: "py38-pytest53" - name: "ubuntu-py35" python: "3.5" @@ -58,6 +64,10 @@ jobs: python: "3.8" os: ubuntu-latest tox_env: "py38" + - name: "ubuntu-py38-pytest53" + python: "3.8" + os: ubuntu-latest + tox_env: "py38-pytest53" - name: "linting" python: "3.7" diff --git a/CHANGELOG.rst b/CHANGELOG.rst index bd7dda6..1753b3c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,11 @@ CHANGELOG ========= +0.3.1 (2020-05-20) +------------------ + +* Fix pytest 5.4 support. + 0.3.0 (2020-01-22) ------------------ diff --git a/pytest_subtests.py b/pytest_subtests.py index f6246af..efe2aa7 100644 --- a/pytest_subtests.py +++ b/pytest_subtests.py @@ -117,7 +117,13 @@ def _capturing_output(self): option = self.request.config.getoption("capture", None) # capsys or capfd are active, subtest should not capture - capture_fixture_active = hasattr(self.request.node, "_capture_fixture") + + # pytest<5.4 support: node holds the active fixture + capture_fixture_active = getattr(self.request.node, "_capture_fixture", None) + if capture_fixture_active is None: + # pytest>=5.4 support: capture manager plugin holds the active fixture + capman = self.request.config.pluginmanager.getplugin("capturemanager") + capture_fixture_active = getattr(capman, "_capture_fixture", None) if option == "sys" and not capture_fixture_active: fixture = CaptureFixture(SysCapture, self.request) diff --git a/tox.ini b/tox.ini index bc588b5..35fc081 100644 --- a/tox.ini +++ b/tox.ini @@ -1,10 +1,12 @@ [tox] -envlist = py34,py35,py36,py37,pypy3,linting +envlist = py35,py36,py37,py38,py38-pytest53,pypy3,linting [testenv] passenv = USER USERNAME TRAVIS PYTEST_ADDOPTS deps = pytest-xdist>=1.28 + pytest53: pytest ==5.3.5 + commands = pytest {posargs:tests}