Skip to content

Commit fafb327

Browse files
aiskzooba
andauthored
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 1d75fa4 commit fafb327

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Lib/test/test_subprocess.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -835,16 +835,25 @@ def is_env_var_to_ignore(n):
835835
if not is_env_var_to_ignore(k)]
836836
self.assertEqual(child_env_names, [])
837837

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

849858
def test_invalid_cmd(self):
850859
# null character in the command name

0 commit comments

Comments
 (0)