Merge pull request #6989 from blueyed/fix-test
This commit is contained in:
commit
b02b0b610b
|
@ -1,9 +1,11 @@
|
||||||
|
import copy
|
||||||
import inspect
|
import inspect
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from _pytest import deprecated
|
from _pytest import deprecated
|
||||||
from _pytest import nodes
|
from _pytest import nodes
|
||||||
|
from _pytest.config import Config
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.filterwarnings("default")
|
@pytest.mark.filterwarnings("default")
|
||||||
|
@ -33,7 +35,7 @@ def test_pytest_collect_module_deprecated(attribute):
|
||||||
getattr(pytest.collect, attribute)
|
getattr(pytest.collect, attribute)
|
||||||
|
|
||||||
|
|
||||||
def test_terminal_reporter_writer_attr(pytestconfig):
|
def test_terminal_reporter_writer_attr(pytestconfig: Config) -> None:
|
||||||
"""Check that TerminalReporter._tw is also available as 'writer' (#2984)
|
"""Check that TerminalReporter._tw is also available as 'writer' (#2984)
|
||||||
This attribute has been deprecated in 5.4.
|
This attribute has been deprecated in 5.4.
|
||||||
"""
|
"""
|
||||||
|
@ -44,15 +46,22 @@ def test_terminal_reporter_writer_attr(pytestconfig):
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
terminal_reporter = pytestconfig.pluginmanager.get_plugin("terminalreporter")
|
terminal_reporter = pytestconfig.pluginmanager.get_plugin("terminalreporter")
|
||||||
expected_tw = terminal_reporter._tw
|
original_tw = terminal_reporter._tw
|
||||||
|
|
||||||
with pytest.warns(pytest.PytestDeprecationWarning):
|
with pytest.warns(pytest.PytestDeprecationWarning) as cw:
|
||||||
assert terminal_reporter.writer is expected_tw
|
assert terminal_reporter.writer is original_tw
|
||||||
|
assert len(cw) == 1
|
||||||
|
assert cw[0].filename == __file__
|
||||||
|
|
||||||
with pytest.warns(pytest.PytestDeprecationWarning):
|
new_tw = copy.copy(original_tw)
|
||||||
terminal_reporter.writer = expected_tw
|
with pytest.warns(pytest.PytestDeprecationWarning) as cw:
|
||||||
|
terminal_reporter.writer = new_tw
|
||||||
assert terminal_reporter._tw is expected_tw
|
try:
|
||||||
|
assert terminal_reporter._tw is new_tw
|
||||||
|
finally:
|
||||||
|
terminal_reporter.writer = original_tw
|
||||||
|
assert len(cw) == 2
|
||||||
|
assert cw[0].filename == cw[1].filename == __file__
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("plugin", sorted(deprecated.DEPRECATED_EXTERNAL_PLUGINS))
|
@pytest.mark.parametrize("plugin", sorted(deprecated.DEPRECATED_EXTERNAL_PLUGINS))
|
||||||
|
|
Loading…
Reference in New Issue