From 6d83329622d6705f0c074be0574dd4f3e2e7e1cf Mon Sep 17 00:00:00 2001 From: Kale Kundert Date: Sat, 9 Oct 2021 13:28:27 -0400 Subject: [PATCH 1/3] Ignore unavoidable warning about private pytest classes --- pytest_subtests.py | 18 ++++++++++++++++-- tests/test_subtests.py | 15 --------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/pytest_subtests.py b/pytest_subtests.py index dc9a71c..389b853 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 @@ -200,6 +202,18 @@ def make_call_info(exc_info, *, start, stop, duration, when): # support for pytest<6: didn't have a duration parameter then 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: diff --git a/tests/test_subtests.py b/tests/test_subtests.py index 3ce9e15..868cb08 100644 --- a/tests/test_subtests.py +++ b/tests/test_subtests.py @@ -2,21 +2,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: """ From 221928cafe631559f5e0a56c4710ac24b21807f7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 9 Oct 2021 17:35:14 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pytest_subtests.py | 9 +++++---- tests/test_subtests.py | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pytest_subtests.py b/pytest_subtests.py index 389b853..5fce369 100644 --- a/pytest_subtests.py +++ b/pytest_subtests.py @@ -202,19 +202,20 @@ def make_call_info(exc_info, *, start, stop, duration, when): # support for pytest<6: didn't have a duration parameter then 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, + "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 868cb08..2e77d73 100644 --- a/tests/test_subtests.py +++ b/tests/test_subtests.py @@ -2,6 +2,7 @@ import pytest + @pytest.mark.parametrize("mode", ["normal", "xdist"]) class TestFixture: """ From f45ad07eba1afdcd3c0b6ac854e95abed9a94b63 Mon Sep 17 00:00:00 2001 From: Kale Kundert Date: Sat, 9 Oct 2021 13:40:25 -0400 Subject: [PATCH 3/3] Remove warning workaround from README --- README.rst | 15 --------------- 1 file changed, 15 deletions(-) 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 ------------