Skip to content

Commit

Permalink
fix: don't break on doctests (#109)
Browse files Browse the repository at this point in the history
Co-authored-by: Tom Forbes <tom@tomforb.es>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 22, 2022
1 parent 2e3ac65 commit bf16fbd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pytest_socket.py
Expand Up @@ -112,7 +112,12 @@ def pytest_runtest_setup(item) -> None:
This is the bulk of the logic for the plugin.
As the logic can be extensive, this method is allowed complexity.
It may be refactored in the future to be more readable.
If the given item is not a function test (i.e a DoctestItem)
or otherwise has no support for fixtures, skip it.
"""
if not hasattr(item, "fixturenames"):
return

# If test has the `enable_socket` marker, we accept this as most explicit.
if "socket_enabled" in item.fixturenames or item.get_closest_marker(
Expand Down
14 changes: 14 additions & 0 deletions tests/test_doctest.py
@@ -0,0 +1,14 @@
def test_function_with_doctest(testdir):
testdir.makepyfile(
'''
def my_sum(a, b):
"""Sum two values.
>>> my_sum(1, 1)
2
"""
return a + b
'''
)
result = testdir.runpytest("--doctest-modules")
result.assert_outcomes(passed=1)

0 comments on commit bf16fbd

Please sign in to comment.