python / python/cpython

`test_subprocess` is flaky under `PYTHONWARNINGS=ignore`

Open
#138,636 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.