Skip to content

Commit

Permalink
Merge pull request pytest-dev#32 from nicoddemus/pytest6-support
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus authored Aug 1, 2020
2 parents c1ec643 + 1ebc543 commit 96fc692
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -68,6 +72,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"
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

0.3.2 (2020-08-01)
------------------

* Fix pytest 6.0 support.

0.3.1 (2020-05-20)
------------------

Expand Down
27 changes: 22 additions & 5 deletions pytest_subtests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
import time
from contextlib import contextmanager
from time import monotonic

import attr
import pytest
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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())

Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -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}
Expand Down

0 comments on commit 96fc692

Please sign in to comment.