@@ -80,7 +80,16 @@ def test_as_import(script):
80
80
81
81
class TestPipTestEnvironment :
82
82
83
- def run_with_log_command (self , script , sub_string ):
83
+ def run_stderr_with_prefix (self , script , prefix , ** kwargs ):
84
+ """
85
+ Call run() that prints stderr with the given prefix.
86
+ """
87
+ text = '{}: hello, world\\ n' .format (prefix )
88
+ command = 'import sys; sys.stderr.write("{}")' .format (text )
89
+ args = [sys .executable , '-c' , command ]
90
+ script .run (* args , ** kwargs )
91
+
92
+ def run_with_log_command (self , script , sub_string , ** kwargs ):
84
93
"""
85
94
Call run() on a command that logs a "%"-style format string using
86
95
the given substring as the string's replacement field.
@@ -90,15 +99,6 @@ def run_with_log_command(self, script, sub_string):
90
99
"logging.getLogger().info('sub: {}', 'foo')"
91
100
).format (sub_string )
92
101
args = [sys .executable , '-c' , command ]
93
- script .run (* args )
94
-
95
- def run_stderr_with_prefix (self , script , prefix , ** kwargs ):
96
- """
97
- Call run() that prints stderr with the given prefix.
98
- """
99
- text = '{}: hello, world\\ n' .format (prefix )
100
- command = 'import sys; sys.stderr.write("{}")' .format (text )
101
- args = [sys .executable , '-c' , command ]
102
102
script .run (* args , ** kwargs )
103
103
104
104
@pytest .mark .parametrize ('prefix' , (
@@ -162,8 +162,13 @@ def test_run__logging_error(self, script):
162
162
163
163
expected_start = 'stderr has a logging error, which is never allowed'
164
164
with assert_error_startswith (RuntimeError , expected_start ):
165
- # Pass a bad substitution string.
166
- self .run_with_log_command (script , sub_string = '{!r}' )
165
+ # Pass a bad substitution string. Also, pass
166
+ # allow_stderr_error=True to check that the RuntimeError occurs
167
+ # even under the stricter test condition of when we are allowing
168
+ # other types of errors.
169
+ self .run_with_log_command (
170
+ script , sub_string = '{!r}' , allow_stderr_error = True ,
171
+ )
167
172
168
173
def test_run__allow_stderr_error_false_error_with_expect_error (
169
174
self , script ,
0 commit comments