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

Ignore unavoidable warning about private pytest classes #52

Merged
merged 4 commits into from
Oct 11, 2021
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
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