`test_subprocess` is flaky under `PYTHONWARNINGS=ignore`
Open
Nobody has claimed this yet.
tests
topic-subprocess
type-bug
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
Description
Feature or enhancement
Proposal:
make test
my env has a export PYTHONWARNINGS=ignore
make test will fall
FAIL: test_encoding_warning (test.test_subprocess.RunFuncTestCase.test_encoding_warning)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/hyi/prs/cpython/Lib/test/test_subprocess.py", line 1837, in test_encoding_warning
self.assertEqual(len(lines), 2, lines)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 0 != 2 : []
at first I thought it is not a big deal
but I checked the code
class Test_TextTestRunner(unittest.TestCase):
"""Tests for TextTestRunner."""
def setUp(self):
# clean the environment from pre-existing PYTHONWARNINGS to make
# test_warnings results consistent
self.pythonwarnings = os.environ.get('PYTHONWARNINGS')
if self.pythonwarnings:
del os.environ['PYTHONWARNINGS']
def tearDown(self):
# bring back pre-existing PYTHONWARNINGS if present
if self.pythonwarnings:
existing code can aviod this.
so I thought it may be can enhance
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs
- gh-138637
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Lib/test/test_subprocess.py at RunFuncTestCase.test_encoding_warning, then review the shown PYTHONWARNINGS cleanup pattern in the relevant test code. Run make test with PYTHONWARNINGS=ignore and verify the subprocess warning test produces the expected two lines without disturbing the existing environment handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100