Skip to content

Commit 42d157b

Browse files
committed
Call resetwarnings() in a few places.
This is needed because unit tests are now run with "-W error" on the command line in CI (pythonGH-128770). We want to start with an empty list of filters to avoid supurious errors.
1 parent 4f11910 commit 42d157b

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

‎Lib/test/test_free_threading/test_races.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ def set_recursion_limit():
291291
class TestWarningsRaces(TestBase):
292292
def setUp(self):
293293
self.saved_filters = warnings.filters[:]
294+
warnings.resetwarnings()
294295
# Add multiple filters to the list to increase odds of race.
295296
for lineno in range(20):
296297
warnings.filterwarnings('ignore', message='not matched', category=Warning, lineno=lineno)

‎Lib/test/test_warnings/__init__.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,10 @@ class AsyncTests(BaseTest):
15351535
the context manager uses a context variable.
15361536
"""
15371537

1538+
def setUp(self):
1539+
super().setUp()
1540+
self.module.resetwarnings()
1541+
15381542
@unittest.skipIf(not sys.flags.context_aware_warnings,
15391543
"requires context aware warnings")
15401544
def test_async_context(self):
@@ -1627,6 +1631,10 @@ class ThreadTests(BaseTest):
16271631
ENABLE_THREAD_TESTS = (sys.flags.context_aware_warnings and
16281632
sys.flags.thread_inherit_context)
16291633

1634+
def setUp(self):
1635+
super().setUp()
1636+
self.module.resetwarnings()
1637+
16301638
@unittest.skipIf(not ENABLE_THREAD_TESTS,
16311639
"requires thread-safe warnings flags")
16321640
def test_threaded_context(self):

0 commit comments

Comments
 (0)