(result: TestResult, runtests: RunTests,
display_failure: bool = True)
| 187 | |
| 188 | |
| 189 | def _runtest_env_changed_exc(result: TestResult, runtests: RunTests, |
| 190 | display_failure: bool = True) -> None: |
| 191 | # Handle exceptions, detect environment changes. |
| 192 | stdout = get_colors(file=sys.stdout) |
| 193 | stderr = get_colors(file=sys.stderr) |
| 194 | |
| 195 | # Reset the environment_altered flag to detect if a test altered |
| 196 | # the environment |
| 197 | support.environment_altered = False |
| 198 | |
| 199 | pgo = runtests.pgo |
| 200 | if pgo: |
| 201 | display_failure = False |
| 202 | quiet = runtests.quiet |
| 203 | |
| 204 | test_name = result.test_name |
| 205 | try: |
| 206 | clear_caches() |
| 207 | support.gc_collect() |
| 208 | |
| 209 | with saved_test_environment(test_name, |
| 210 | runtests.verbose, quiet, pgo=pgo): |
| 211 | _load_run_test(result, runtests) |
| 212 | except support.ResourceDenied as exc: |
| 213 | if not quiet and not pgo: |
| 214 | print( |
| 215 | f"{stdout.YELLOW}{test_name} skipped -- {exc}{stdout.RESET}", |
| 216 | flush=True, |
| 217 | ) |
| 218 | result.state = State.RESOURCE_DENIED |
| 219 | return |
| 220 | except unittest.SkipTest as exc: |
| 221 | if not quiet and not pgo: |
| 222 | print( |
| 223 | f"{stdout.YELLOW}{test_name} skipped -- {exc}{stdout.RESET}", |
| 224 | flush=True, |
| 225 | ) |
| 226 | result.state = State.SKIPPED |
| 227 | return |
| 228 | except support.TestFailedWithDetails as exc: |
| 229 | msg = f"{stderr.RED}test {test_name} failed{stderr.RESET}" |
| 230 | if display_failure: |
| 231 | msg = f"{stderr.RED}{msg} -- {exc}{stderr.RESET}" |
| 232 | print(msg, file=sys.stderr, flush=True) |
| 233 | result.state = State.FAILED |
| 234 | result.errors = exc.errors |
| 235 | result.failures = exc.failures |
| 236 | result.stats = exc.stats |
| 237 | return |
| 238 | except support.TestFailed as exc: |
| 239 | msg = f"{stderr.RED}test {test_name} failed{stderr.RESET}" |
| 240 | if display_failure: |
| 241 | msg = f"{stderr.RED}{msg} -- {exc}{stderr.RESET}" |
| 242 | print(msg, file=sys.stderr, flush=True) |
| 243 | result.state = State.FAILED |
| 244 | result.stats = exc.stats |
| 245 | return |
| 246 | except support.TestDidNotRun: |
no test coverage detected