Skip to content

Commit

Permalink
Adapt to Node API change
Browse files Browse the repository at this point in the history
The Node API was changed in pytest 5.4 in
pytest-dev/pytest#5975.

This commit adds support for the new API but maintains backwards
compatiblity.

Closes: #11
  • Loading branch information
twmr committed Apr 1, 2020
1 parent e72d593 commit 5123745
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
###
- Adapt to Node API changes in pytest-5.4 (Fixes #11)

## [0.2.2] - 2019-05-24
###
- Add hack for handling mock style objects
Expand Down
30 changes: 24 additions & 6 deletions pytest_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@
import sys
import traceback

from pkg_resources import parse_version

import _pytest.doctest
import pytest


PYTEST_PRE_54 = parse_version(pytest.__version__) < parse_version('5.4')


def pairwise(iterable):
"""
s -> (s0,s1), (s1,s2), (s2, s3), ...
Expand All @@ -41,9 +46,15 @@ def pytest_collect_file(path, parent):
config = parent.config
if path.ext == ".py":
if config.option.doctestmodules:
return SphinxDoctestModule(path, parent)
if PYTEST_PRE_54:
return SphinxDoctestModule(path, parent)
else:
return SphinxDoctestModule.from_parent(parent, fspath=path)
elif _is_doctest(config, path, parent):
return SphinxDoctestTextfile(path, parent)
if PYTEST_PRE_54:
return SphinxDoctestTextfile(path, parent)
else:
return SphinxDoctestTextfile.from_parent(parent, fspath=path)


def _is_doctest(config, path, parent):
Expand Down Expand Up @@ -343,8 +354,11 @@ def collect(self):
docstring=text)

if test.examples:
yield _pytest.doctest.DoctestItem(
test.name, self, runner, test)
if PYTEST_PRE_54:
yield _pytest.doctest.DoctestItem(test.name, self, runner, test)
else:
yield _pytest.doctest.DoctestItem.from_parent(
parent=self, name=test.name, runner=runner, dtest=test)


class SphinxDoctestModule(pytest.Module):
Expand Down Expand Up @@ -395,5 +409,9 @@ def _find(self, tests, obj, name, module, source_lines,

for test in finder.find(module, module.__name__):
if test.examples:
yield _pytest.doctest.DoctestItem(
test.name, self, runner, test)
if PYTEST_PRE_54:
yield _pytest.doctest.DoctestItem(
test.name, self, runner, test)
else:
yield _pytest.doctest.DoctestItem.from_parent(
parent=self, name=test.name, runner=runner, dtest=test)

0 comments on commit 5123745

Please sign in to comment.