()
| 66 | |
| 67 | |
| 68 | def test_ignore_warning(): |
| 69 | # This check that ignore_warning decorator and context manager are working |
| 70 | # as expected |
| 71 | def _warning_function(): |
| 72 | warnings.warn("deprecation warning", DeprecationWarning) |
| 73 | |
| 74 | def _multiple_warning_function(): |
| 75 | warnings.warn("deprecation warning", DeprecationWarning) |
| 76 | warnings.warn("deprecation warning") |
| 77 | |
| 78 | # Check the function directly |
| 79 | with warnings.catch_warnings(): |
| 80 | warnings.simplefilter("error") |
| 81 | |
| 82 | ignore_warnings(_warning_function) |
| 83 | ignore_warnings(_warning_function, category=DeprecationWarning) |
| 84 | |
| 85 | with pytest.warns(DeprecationWarning): |
| 86 | ignore_warnings(_warning_function, category=UserWarning)() |
| 87 | |
| 88 | with pytest.warns() as record: |
| 89 | ignore_warnings(_multiple_warning_function, category=FutureWarning)() |
| 90 | assert len(record) == 2 |
| 91 | assert isinstance(record[0].message, DeprecationWarning) |
| 92 | assert isinstance(record[1].message, UserWarning) |
| 93 | |
| 94 | with pytest.warns() as record: |
| 95 | ignore_warnings(_multiple_warning_function, category=UserWarning)() |
| 96 | assert len(record) == 1 |
| 97 | assert isinstance(record[0].message, DeprecationWarning) |
| 98 | |
| 99 | with warnings.catch_warnings(): |
| 100 | warnings.simplefilter("error") |
| 101 | |
| 102 | ignore_warnings(_warning_function, category=(DeprecationWarning, UserWarning)) |
| 103 | |
| 104 | # Check the decorator |
| 105 | @ignore_warnings |
| 106 | def decorator_no_warning(): |
| 107 | _warning_function() |
| 108 | _multiple_warning_function() |
| 109 | |
| 110 | @ignore_warnings(category=(DeprecationWarning, UserWarning)) |
| 111 | def decorator_no_warning_multiple(): |
| 112 | _multiple_warning_function() |
| 113 | |
| 114 | @ignore_warnings(category=DeprecationWarning) |
| 115 | def decorator_no_deprecation_warning(): |
| 116 | _warning_function() |
| 117 | |
| 118 | @ignore_warnings(category=UserWarning) |
| 119 | def decorator_no_user_warning(): |
| 120 | _warning_function() |
| 121 | |
| 122 | @ignore_warnings(category=DeprecationWarning) |
| 123 | def decorator_no_deprecation_multiple_warning(): |
| 124 | _multiple_warning_function() |
| 125 |
nothing calls this directly
no test coverage detected
searching dependent graphs…