Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to Node API change #12

Merged
merged 1 commit into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this adds quite some overhead.
See pytest-dev/pytest-django#826

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for the change itself you could also just look for the from_parent attribute, or require pytest 5.4 (like pytest-asyncio does it). I'd prefer the former.

Copy link
Owner Author

@twmr twmr Apr 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx @blueyed for this info! I've just fixed this in the master branch.


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)