|
2 | 2 | from __future__ import annotations |
3 | 3 |
|
4 | 4 | import ast |
| 5 | +import enum |
5 | 6 | import hashlib |
6 | 7 | import os |
7 | 8 | import pickle |
|
11 | 12 | import unittest |
12 | 13 | from collections import defaultdict |
13 | 14 | from pathlib import Path |
14 | | -from typing import TYPE_CHECKING, Callable, Optional |
| 15 | +from typing import TYPE_CHECKING, Callable, Optional, final |
15 | 16 |
|
16 | 17 | if TYPE_CHECKING: |
17 | 18 | from codeflash.discovery.functions_to_optimize import FunctionToOptimize |
18 | 19 |
|
19 | | -import pytest |
20 | 20 | from pydantic.dataclasses import dataclass |
21 | 21 | from rich.panel import Panel |
22 | 22 | from rich.text import Text |
|
35 | 35 | from codeflash.verification.verification_utils import TestConfig |
36 | 36 |
|
37 | 37 |
|
| 38 | +@final |
| 39 | +class PytestExitCode(enum.IntEnum): # don't need to import entire pytest just for this |
| 40 | + #: Tests passed. |
| 41 | + OK = 0 |
| 42 | + #: Tests failed. |
| 43 | + TESTS_FAILED = 1 |
| 44 | + #: pytest was interrupted. |
| 45 | + INTERRUPTED = 2 |
| 46 | + #: An internal error got in the way. |
| 47 | + INTERNAL_ERROR = 3 |
| 48 | + #: pytest was misused. |
| 49 | + USAGE_ERROR = 4 |
| 50 | + #: pytest couldn't find tests. |
| 51 | + NO_TESTS_COLLECTED = 5 |
| 52 | + |
| 53 | + |
38 | 54 | @dataclass(frozen=True) |
39 | 55 | class TestFunction: |
40 | 56 | function_name: str |
@@ -412,15 +428,15 @@ def discover_tests_pytest( |
412 | 428 | error_section = match.group(1) if match else result.stdout |
413 | 429 |
|
414 | 430 | logger.warning( |
415 | | - f"Failed to collect tests. Pytest Exit code: {exitcode}={pytest.ExitCode(exitcode).name}\n {error_section}" |
| 431 | + f"Failed to collect tests. Pytest Exit code: {exitcode}={PytestExitCode(exitcode).name}\n {error_section}" |
416 | 432 | ) |
417 | 433 | if "ModuleNotFoundError" in result.stdout: |
418 | 434 | match = ImportErrorPattern.search(result.stdout).group() |
419 | 435 | panel = Panel(Text.from_markup(f"⚠️ {match} ", style="bold red"), expand=False) |
420 | 436 | console.print(panel) |
421 | 437 |
|
422 | 438 | elif 0 <= exitcode <= 5: |
423 | | - logger.warning(f"Failed to collect tests. Pytest Exit code: {exitcode}={pytest.ExitCode(exitcode).name}") |
| 439 | + logger.warning(f"Failed to collect tests. Pytest Exit code: {exitcode}={PytestExitCode(exitcode).name}") |
424 | 440 | else: |
425 | 441 | logger.warning(f"Failed to collect tests. Pytest Exit code: {exitcode}") |
426 | 442 | console.rule() |
|
0 commit comments