diff --git a/README.rst b/README.rst index 55a5773..7a83615 100644 --- a/README.rst +++ b/README.rst @@ -40,21 +40,6 @@ Requirements * ``Python`` >= 3.5. * ``pytest`` >= 5.3. -pytest 6.2+ -^^^^^^^^^^^ - -``pytest 6.2`` now issues a warning when internal classes are used by third-party code, -which is the case for ``pytest-subtests`` which needs to use some internal classes -to integrate with other pytest features (such as capturing and debugging). - -For now users can ignore those warnings by adding this to their configuration file: - -.. code-block:: ini - - [pytest] - filterwarnings = - ignore:A private pytest class or function was used.:pytest.PytestDeprecationWarning - Installation ------------ diff --git a/pytest_subtests.py b/pytest_subtests.py index dc9a71c..5fce369 100644 --- a/pytest_subtests.py +++ b/pytest_subtests.py @@ -138,9 +138,11 @@ def _capturing_output(self): capture_fixture_active = getattr(capman, "_capture_fixture", None) if option == "sys" and not capture_fixture_active: - fixture = CaptureFixture(SysCapture, self.request) + with ignore_pytest_private_warning(): + fixture = CaptureFixture(SysCapture, self.request) elif option == "fd" and not capture_fixture_active: - fixture = CaptureFixture(FDCapture, self.request) + with ignore_pytest_private_warning(): + fixture = CaptureFixture(FDCapture, self.request) else: fixture = None @@ -201,6 +203,19 @@ def make_call_info(exc_info, *, start, stop, duration, when): return CallInfo(None, exc_info, start=start, stop=stop, when=when) +@contextmanager +def ignore_pytest_private_warning(): + import warnings + + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", + "A private pytest class or function was used.", + category=pytest.PytestDeprecationWarning, + ) + yield + + @attr.s class Captured: out = attr.ib(default="", type=str) diff --git a/tests/test_subtests.py b/tests/test_subtests.py index 3ce9e15..2e77d73 100644 --- a/tests/test_subtests.py +++ b/tests/test_subtests.py @@ -3,20 +3,6 @@ import pytest -@pytest.fixture(autouse=True) -def ignore_private_class_warning(testdir): - """ - Make every test in this file ignore the warning about using private pytest classes; - It is a risk we are willing to take in this plugin. - """ - testdir.makeini( - """ - [pytest] - filterwarnings = ignore:A private pytest class - """ - ) - - @pytest.mark.parametrize("mode", ["normal", "xdist"]) class TestFixture: """