()
| 1919 | reason="uses deprecated thread-unsafe warnings control utilities" |
| 1920 | ) |
| 1921 | def test_suppress_warnings_record(): |
| 1922 | # NOTE(seberg): We test for the DeprecationWarning mainly because on |
| 1923 | # free-threaded Python an "ignore" warning filters seem to collide with |
| 1924 | # parts of what `suppress_warnings` does (if used more than once?). |
| 1925 | with pytest.warns( |
| 1926 | DeprecationWarning, |
| 1927 | match="suppression and assertion utilities are deprecated"): |
| 1928 | sup = suppress_warnings() |
| 1929 | log1 = sup.record() |
| 1930 | |
| 1931 | with sup: |
| 1932 | log2 = sup.record(message='Some other warning 2') |
| 1933 | sup.filter(message='Some warning') |
| 1934 | warnings.warn('Some warning') |
| 1935 | warnings.warn('Some other warning') |
| 1936 | warnings.warn('Some other warning 2') |
| 1937 | |
| 1938 | assert_equal(len(sup.log), 2) |
| 1939 | assert_equal(len(log1), 1) |
| 1940 | assert_equal(len(log2), 1) |
| 1941 | assert_equal(log2[0].message.args[0], 'Some other warning 2') |
| 1942 | |
| 1943 | # Do it again, with the same context to see if some warnings survived: |
| 1944 | with sup: |
| 1945 | log2 = sup.record(message='Some other warning 2') |
| 1946 | sup.filter(message='Some warning') |
| 1947 | warnings.warn('Some warning') |
| 1948 | warnings.warn('Some other warning') |
| 1949 | warnings.warn('Some other warning 2') |
| 1950 | |
| 1951 | assert_equal(len(sup.log), 2) |
| 1952 | assert_equal(len(log1), 1) |
| 1953 | assert_equal(len(log2), 1) |
| 1954 | assert_equal(log2[0].message.args[0], 'Some other warning 2') |
| 1955 | |
| 1956 | # Test nested: |
| 1957 | with suppress_warnings() as sup: |
| 1958 | sup.record() |
| 1959 | with suppress_warnings() as sup2: |
| 1960 | sup2.record(message='Some warning') |
| 1961 | warnings.warn('Some warning') |
| 1962 | warnings.warn('Some other warning') |
| 1963 | assert_equal(len(sup2.log), 1) |
| 1964 | # includes a DeprecationWarning for suppress_warnings |
| 1965 | assert_equal(len(sup.log), 2) |
| 1966 | |
| 1967 | |
| 1968 | @pytest.mark.thread_unsafe( |
nothing calls this directly
no test coverage detected
searching dependent graphs…