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

fix: don't break on doctests #109

Merged
merged 2 commits into from
Jan 22, 2022
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
5 changes: 5 additions & 0 deletions pytest_socket.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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)