|
6 | 6 |
|
7 | 7 | import inspect |
8 | 8 | import sys |
| 9 | +import os |
9 | 10 | from importlib import import_module |
10 | 11 |
|
11 | 12 | from makefun import add_signature_parameters, wraps |
|
30 | 31 | from .common_others import get_function_host |
31 | 32 | from .common_pytest_marks import make_marked_parameter_value, get_param_argnames_as_list, \ |
32 | 33 | get_pytest_parametrize_marks, get_pytest_usefixture_marks, PYTEST3_OR_GREATER, PYTEST6_OR_GREATER, \ |
33 | | - PYTEST38_OR_GREATER, PYTEST34_OR_GREATER, PYTEST33_OR_GREATER |
| 34 | + PYTEST38_OR_GREATER, PYTEST34_OR_GREATER, PYTEST33_OR_GREATER, PYTEST32_OR_GREATER |
34 | 35 | from .common_pytest_lazy_values import is_lazy_value, is_lazy |
35 | 36 |
|
36 | 37 |
|
@@ -65,6 +66,18 @@ def _decorate(f): |
65 | 66 | return _decorate |
66 | 67 |
|
67 | 68 |
|
| 69 | +def pytest_is_running(): |
| 70 | + """Return True if the current process is a pytest run |
| 71 | +
|
| 72 | + See https://stackoverflow.com/questions/25188119/test-if-code-is-executed-from-within-a-py-test-session |
| 73 | + """ |
| 74 | + if PYTEST32_OR_GREATER: |
| 75 | + return "PYTEST_CURRENT_TEST" in os.environ |
| 76 | + else: |
| 77 | + import re |
| 78 | + return any(re.findall(r'pytest|py.test', sys.argv[0])) |
| 79 | + |
| 80 | + |
68 | 81 | def remove_duplicates(lst): |
69 | 82 | dset = set() |
70 | 83 | # relies on the fact that dset.add() always returns None. |
@@ -619,7 +632,9 @@ def __init__(self, func): |
619 | 632 |
|
620 | 633 | self.config = PYTEST_CONFIG |
621 | 634 | if self.config is None: |
622 | | - raise ValueError("Internal error - config has not been correctly loaded. Please report") |
| 635 | + # only raise if we are in pytest, otherwise silently skip |
| 636 | + if pytest_is_running(): |
| 637 | + raise ValueError("Internal error - config has not been correctly loaded. Please report") |
623 | 638 |
|
624 | 639 | self.function = func |
625 | 640 | self.definition = MiniFuncDef(func.__name__) |
|
0 commit comments