Пример #1
0
def test_functional(
    test_file: FunctionalTestFile, recwarn: WarningsRecorder, pytestconfig: Config
) -> None:
    __tracebackhide__ = True  # pylint: disable=unused-variable
    if UPDATE_FILE.exists():
        lint_test: Union[
            LintModuleOutputUpdate, testutils.LintModuleTest
        ] = LintModuleOutputUpdate(test_file, pytestconfig)
    else:
        lint_test = testutils.LintModuleTest(test_file, pytestconfig)
    lint_test.setUp()
    lint_test.runTest()
    warning = None
    try:
        # Catch <unknown>:x: DeprecationWarning: invalid escape sequence
        # so it's not shown during tests
        warning = recwarn.pop()
    except AssertionError:
        pass
    if warning is not None:
        if (
            test_file.base in TEST_WITH_EXPECTED_DEPRECATION
            and sys.version_info.minor > 5
        ):
            assert issubclass(warning.category, DeprecationWarning)
            assert "invalid escape sequence" in str(warning.message)
Пример #2
0
def test_recwarn_captures_deprecation_warning(recwarn: WarningsRecorder) -> None:
    """
    Check that recwarn can capture DeprecationWarning by default
    without custom filterwarnings (see #8666).
    """
    warnings.warn(DeprecationWarning("some deprecation"))
    assert len(recwarn) == 1
    assert recwarn.pop(DeprecationWarning)
Пример #3
0
 def test_recording(self):
     rec = WarningsRecorder()
     with rec:
         assert not rec.list
         warnings.warn_explicit("hello", UserWarning, "xyz", 13)
         assert len(rec.list) == 1
         warnings.warn(DeprecationWarning("hello"))
         assert len(rec.list) == 2
         warn = rec.pop()
         assert str(warn.message) == "hello"
         values = rec.list
         rec.clear()
         assert len(rec.list) == 0
         assert values is rec.list
         pytest.raises(AssertionError, "rec.pop()")
Пример #4
0
 def test_recording(self):
     rec = WarningsRecorder()
     with rec:
         assert not rec.list
         warnings.warn_explicit("hello", UserWarning, "xyz", 13)
         assert len(rec.list) == 1
         warnings.warn(DeprecationWarning("hello"))
         assert len(rec.list) == 2
         warn = rec.pop()
         assert str(warn.message) == "hello"
         values = rec.list
         rec.clear()
         assert len(rec.list) == 0
         assert values is rec.list
         pytest.raises(AssertionError, rec.pop)
Пример #5
0
def test_WarningRecorder(recwarn):
    showwarning = py.std.warnings.showwarning
    rec = WarningsRecorder()
    assert py.std.warnings.showwarning != showwarning
    assert not rec.list
    py.std.warnings.warn_explicit("hello", UserWarning, "xyz", 13)
    assert len(rec.list) == 1
    py.std.warnings.warn(DeprecationWarning("hello"))
    assert len(rec.list) == 2
    warn = rec.pop()
    assert str(warn.message) == "hello"
    l = rec.list
    rec.clear()
    assert len(rec.list) == 0
    assert l is rec.list
    pytest.raises(AssertionError, "rec.pop()")
    rec.finalize()
    assert showwarning == py.std.warnings.showwarning
Пример #6
0
    def test_recording(self, recwarn):
        showwarning = py.std.warnings.showwarning
        rec = WarningsRecorder()
        with rec:
            assert py.std.warnings.showwarning != showwarning
            assert not rec.list
            py.std.warnings.warn_explicit("hello", UserWarning, "xyz", 13)
            assert len(rec.list) == 1
            py.std.warnings.warn(DeprecationWarning("hello"))
            assert len(rec.list) == 2
            warn = rec.pop()
            assert str(warn.message) == "hello"
            l = rec.list
            rec.clear()
            assert len(rec.list) == 0
            assert l is rec.list
            pytest.raises(AssertionError, "rec.pop()")

        assert showwarning == py.std.warnings.showwarning
Пример #7
0
def test_recwarn_stacklevel(recwarn: WarningsRecorder) -> None:
    warnings.warn("hello")
    warn = recwarn.pop()
    assert warn.filename == __file__