Skip to content

Commit 03022e4

Browse files
aiskzooba
authored andcommitted
gh-87868: Skip test_one_environment_variable in test_subprocess when the platform or build cannot do that (#113867)
* improve the assert for test_one_environment_variable * skip some test in test_subprocess when python is configured with shared * also skip the test if AddressSanitizer is enabled --------- Co-authored-by: Steve Dower <[email protected]>
1 parent 255872a commit 03022e4

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Lib/test/test_subprocess.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -833,16 +833,25 @@ def is_env_var_to_ignore(n):
833833
if not is_env_var_to_ignore(k)]
834834
self.assertEqual(child_env_names, [])
835835

836+
@unittest.skipIf(sysconfig.get_config_var('Py_ENABLE_SHARED') == 1,
837+
'The Python shared library cannot be loaded '
838+
'without some system environments.')
839+
@unittest.skipIf(check_sanitizer(address=True),
840+
'AddressSanitizer adds to the environment.')
836841
def test_one_environment_variable(self):
837842
newenv = {'fruit': 'orange'}
838843
cmd = [sys.executable, '-c',
839844
'import sys,os;'
840845
'sys.stdout.write("fruit="+os.getenv("fruit"))']
841846
if sys.platform == "win32":
842847
cmd = ["CMD", "/c", "SET", "fruit"]
843-
with subprocess.Popen(cmd, stdout=subprocess.PIPE, env=newenv) as p:
844-
stdout, _ = p.communicate()
845-
self.assertTrue(stdout.startswith(b"fruit=orange"))
848+
with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=newenv) as p:
849+
stdout, stderr = p.communicate()
850+
if p.returncode and support.verbose:
851+
print("STDOUT:", stdout.decode("ascii", "replace"))
852+
print("STDERR:", stderr.decode("ascii", "replace"))
853+
self.assertEqual(p.returncode, 0)
854+
self.assertEqual(stdout.strip(), b"fruit=orange")
846855

847856
def test_invalid_cmd(self):
848857
# null character in the command name

0 commit comments

Comments
 (0)