Skip to content

Commit

Permalink
Adapt to api change in pytest-6.0
Browse files Browse the repository at this point in the history
THe _importconftest method got a new kwarg in pytest-6.0.
  • Loading branch information
twmr committed Aug 5, 2020
1 parent b808b8a commit 4e80e5c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 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).

## [0.3.1] - 2020-08-05
###
- Adapt to importmode API changes in pytest-6.0

## [0.3] - 2020-08-04
###
- Adapt to Node API changes in pytest-5.4 (Fixes #11)
Expand Down
8 changes: 7 additions & 1 deletion pytest_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,13 @@ def collect(self):
class SphinxDoctestModule(pytest.Module):
def collect(self):
if self.fspath.basename == "conftest.py":
module = self.config.pluginmanager._importconftest(self.fspath)
try:
module = self.config.pluginmanager._importconftest(
self.fspath, importmode="prepend"
)
except TypeError:
# pytest < 6.0
module = self.config.pluginmanager._importconftest(self.fspath)
else:
try:
module = self.fspath.pyimport()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def read(fname):

setup(
name="pytest-sphinx",
version="0.3",
version="0.3.1",
author="Thomas Hisch",
author_email="[email protected]",
maintainer="Thomas Hisch",
Expand Down
23 changes: 23 additions & 0 deletions tests/test_python_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,26 @@ def test_workaround_for_doctest_mockobj_bug(testdir):

result = testdir.runpytest("--doctest-modules")
result.stdout.fnmatch_lines(["*=== 1 passed in *"])


def test_with_conftest(testdir):
content = """
\"\"\"
.. testcode::
print('abc')
.. testoutput::
abc
\"\"\"
"""

testdir.maketxtfile(test_something=content)

testdir.makeconftest(content)

# what do we expect?
result = testdir.runpytest("--doctest-modules")
# 2 test passed one test in conftest.py and one in something.py
result.stdout.fnmatch_lines(["*=== 2 passed in *"])

0 comments on commit 4e80e5c

Please sign in to comment.