Skip to content

Commit

Permalink
Make SubTests importable from pytest_subtests (#122)
Browse files Browse the repository at this point in the history
Fixes #121

---------

Co-authored-by: Bruno Oliveira <[email protected]>
  • Loading branch information
jamesbraza and nicoddemus authored Mar 6, 2024
1 parent 760cd7a commit 0700a10
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ UNRELEASED

* Python 3.12 is now officially supported (`#113`_).
* Added typing support (`#115`_).
* ``SubTests`` can be imported from ``pytest_subtests`` to type-annotate the ``subtests`` fixture.

.. _#113: https://github.com/pytest-dev/pytest-subtests/pull/113
.. _#115: https://github.com/pytest-dev/pytest-subtests/pull/115
Expand Down
3 changes: 3 additions & 0 deletions src/pytest_subtests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .plugin import SubTests

__all__ = ["SubTests"]
22 changes: 22 additions & 0 deletions tests/test_subtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,28 @@ def test_foo(subtests):
expected_lines += ["* 1 passed, 3 xfailed, 2 subtests passed in *"]
result.stdout.fnmatch_lines(expected_lines)

def test_typing_exported(
self, pytester: pytest.Pytester, mode: Literal["normal", "xdist"]
) -> None:
pytester.makepyfile(
"""
from pytest_subtests import SubTests
def test_typing_exported(subtests: SubTests) -> None:
assert isinstance(subtests, SubTests)
"""
)
if mode == "normal":
result = pytester.runpytest()
expected_lines = ["collected 1 item"]
else:
assert mode == "xdist"
pytest.importorskip("xdist")
result = pytester.runpytest("-n1")
expected_lines = ["1 worker [1 item]"]
expected_lines += ["* 1 passed *"]
result.stdout.fnmatch_lines(expected_lines)


class TestSubTest:
"""
Expand Down

0 comments on commit 0700a10

Please sign in to comment.