From a4d19e36decf7efc335b0168ff6f7e7e2b1689d5 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 1 Aug 2020 11:48:09 -0300 Subject: [PATCH 1/3] Fix support for pytest 6.0 Fix #31 --- CHANGELOG.rst | 5 +++++ pytest_subtests.py | 27 ++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1753b3c..8555ce9 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,11 @@ CHANGELOG ========= +0.3.2 (2020-08-01) +------------------ + +* Fix pytest 6.0 support. + 0.3.1 (2020-05-20) ------------------ diff --git a/pytest_subtests.py b/pytest_subtests.py index efe2aa7..33d71e2 100644 --- a/pytest_subtests.py +++ b/pytest_subtests.py @@ -1,6 +1,6 @@ import sys +import time from contextlib import contextmanager -from time import monotonic import attr import pytest @@ -74,7 +74,9 @@ def _from_json(cls, reportdict): def _addSubTest(self, test_case, test, exc_info): if exc_info is not None: msg = test._message if isinstance(test._message, str) else None - call_info = CallInfo(None, ExceptionInfo(exc_info), 0, 0, when="call") + call_info = make_call_info( + ExceptionInfo(exc_info), start=0, stop=0, duration=0, when="call" + ) sub_report = SubTestReport.from_item_and_call(item=self, call=call_info) sub_report.context = SubTestContext(msg, dict(test.params)) self.ihook.pytest_runtest_logreport(report=sub_report) @@ -147,7 +149,8 @@ def _capturing_output(self): @contextmanager def test(self, msg=None, **kwargs): - start = monotonic() + start = time.time() + precise_start = time.perf_counter() exc_info = None with self._capturing_output() as captured: @@ -156,9 +159,13 @@ def test(self, msg=None, **kwargs): except (Exception, OutcomeException): exc_info = ExceptionInfo.from_current() - stop = monotonic() + precise_stop = time.perf_counter() + duration = precise_stop - precise_start + stop = time.time() - call_info = CallInfo(None, exc_info, start, stop, when="call") + call_info = make_call_info( + exc_info, start=start, stop=stop, duration=duration, when="call" + ) sub_report = SubTestReport.from_item_and_call(item=self.item, call=call_info) sub_report.context = SubTestContext(msg, kwargs.copy()) @@ -168,6 +175,16 @@ def test(self, msg=None, **kwargs): self.ihook.pytest_runtest_logreport(report=sub_report) +def make_call_info(exc_info, *, start, stop, duration, when): + try: + return CallInfo( + None, exc_info, start=start, stop=stop, duration=duration, when=when + ) + except TypeError: + # support for pytest<6: didn't have a duration parameter then + return CallInfo(None, exc_info, start=start, stop=stop, when=when) + + @attr.s class Captured: out = attr.ib(default="", type=str) From 94918602e2077ea1ee1a9bf2c164544e90c6cf7b Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 1 Aug 2020 11:49:47 -0300 Subject: [PATCH 2/3] Run pytest 5.4 on CI explicitly --- .github/workflows/main.yml | 4 ++++ tox.ini | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e41cfda..e68e32c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -68,6 +68,10 @@ jobs: python: "3.8" os: ubuntu-latest tox_env: "py38-pytest53" + - name: "ubuntu-py38-pytest54" + python: "3.8" + os: ubuntu-latest + tox_env: "py38-pytest54" - name: "linting" python: "3.7" diff --git a/tox.ini b/tox.ini index 35fc081..1dfcd02 100644 --- a/tox.ini +++ b/tox.ini @@ -1,11 +1,12 @@ [tox] -envlist = py35,py36,py37,py38,py38-pytest53,pypy3,linting +envlist = py35,py36,py37,py38,py38-pytest53,py38-pytest54,pypy3,linting [testenv] passenv = USER USERNAME TRAVIS PYTEST_ADDOPTS deps = pytest-xdist>=1.28 pytest53: pytest ==5.3.5 + pytest54: pytest ==5.4.3 commands = pytest {posargs:tests} From 1ebc543d7850f4945b6e1a6ef39b5dee923a1d7d Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 1 Aug 2020 11:59:24 -0300 Subject: [PATCH 3/3] Add missing pytest 5.4 run on Windows --- .github/workflows/main.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e68e32c..f2fad6e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -47,6 +47,10 @@ jobs: python: "3.8" os: windows-latest tox_env: "py38-pytest53" + - name: "windows-py38-pytest54" + python: "3.8" + os: windows-latest + tox_env: "py38-pytest54" - name: "ubuntu-py35" python: "3.5"