Skip to content

Commit

Permalink
Merge pull request #52 from kalekundert/fix-private-warning
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus authored Oct 11, 2021
2 parents 697b761 + e88cbe6 commit 20251da
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 31 deletions.
15 changes: 0 additions & 15 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------

Expand Down
19 changes: 17 additions & 2 deletions pytest_subtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
14 changes: 0 additions & 14 deletions tests/test_subtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down

0 comments on commit 20251da

Please sign in to comment.