Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6ae4667

Browse files
committed
clean the environment from pre-existing PYTHONWARNINGS for test_warnings
1 parent 20ea96f commit 6ae4667

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

Lib/unittest/test/test_runner.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,18 @@ def cleanup2():
139139
class Test_TextTestRunner(unittest.TestCase):
140140
"""Tests for TextTestRunner."""
141141

142+
def setUp(self):
143+
# clean the environment from pre-existing PYTHONWARNINGS to make
144+
# test_warnings results consistent
145+
self.pythonwarnings = os.environ.get('PYTHONWARNINGS')
146+
if self.pythonwarnings:
147+
del os.environ['PYTHONWARNINGS']
148+
149+
def tearDown(self):
150+
# bring back pre-existing PYTHONWARNINGS if present
151+
if self.pythonwarnings:
152+
os.environ['PYTHONWARNINGS'] = self.pythonwarnings
153+
142154
def test_init(self):
143155
runner = unittest.TextTestRunner()
144156
self.assertFalse(runner.failfast)

0 commit comments

Comments
 (0)