|
5 | 5 | _pytestutils_before_global_counter = 0 |
6 | 6 | _pytestutils_before_global_lock = threading.Lock() |
7 | 7 |
|
8 | | -_pytestutils_is_there_any_test_marked_with_focus = False |
9 | | - |
10 | 8 |
|
11 | 9 | def before(before_function): |
12 | 10 | """ |
@@ -56,55 +54,3 @@ def test_it_does_stuff(self): |
56 | 54 |
|
57 | 55 | return pytest.fixture( |
58 | 56 | autouse=True, name=unique_fixture_name)(before_function) |
59 | | - |
60 | | - |
61 | | -def focus(decorated_test): |
62 | | - """ |
63 | | - Decorator for tagging a function or class as being in focus, and to switch the test suite execution to "focused |
64 | | - execution mode". When the test suite is in "focused execution mode", only functions and classes marked with @focus |
65 | | - are run, all others are skipped. |
66 | | -
|
67 | | - When there are no functions/classes marked with @focus, the test suite goes back to the usual mode, and all tests |
68 | | - are run. |
69 | | -
|
70 | | - The focused execution mode is useful for quickly and without needing to edit any more configuration/files selecting |
71 | | - only a subset of the tests for execution, to speed up testing cycles. |
72 | | -
|
73 | | - This decorator is inspired by similar IDE features (e.g. https://blogs.oracle.com/geertjan/run-focused-test-method ) |
74 | | - and other test libraries (e.g. https://medium.com/table-xi/focus-your-rspec-workflow-4cd5798d2a3e ). |
75 | | -
|
76 | | - Limitation when used with Pytest < 3.6: @focus does not extend to nested classes, see |
77 | | - https://github.com/pytest-dev/pytest/issues/199 and https://github.com/pytest-dev/pytest/pull/3317 for details. |
78 | | -
|
79 | | - This feature is broken into several pieces: |
80 | | - * The @focus decorator sets a global variable to trigger the focused execution mode, and additionally marks any |
81 | | - test method or class with the "pytestutils_focus" marker |
82 | | - * In pytestutils_focus.py a pytest plugin is provided that when in focused execution mode, skips any tests not |
83 | | - marked with the "pytestutils_focus" marker |
84 | | - * In conftest.py we enable the pytest plugin |
85 | | - """ |
86 | | - _validate_focus_enabled() |
87 | | - |
88 | | - global _pytestutils_is_there_any_test_marked_with_focus |
89 | | - |
90 | | - _pytestutils_is_there_any_test_marked_with_focus = True |
91 | | - |
92 | | - return pytest.mark.pytestutils_focus(decorated_test) |
93 | | - |
94 | | - |
95 | | -def _validate_focus_enabled(): |
96 | | - if os.environ.get("PYTESTUTILS_ALLOW_FOCUS") in ("1", "true", "yes"): |
97 | | - return |
98 | | - raise RuntimeError(""" |
99 | | -Found tests annotated with @focus decorator, but the PYTESTUTILS_ALLOW_FOCUS environment variable is not set in the |
100 | | -current environment. |
101 | | -
|
102 | | -If you found this error in a CI environment, it means someone committed test code with a @focus annotation -- please |
103 | | -check for and remove it from the codebase. |
104 | | -
|
105 | | -If you found this error and you wanted to use @focus for your own development work, please add a PYTESTUTILS_ALLOW_FOCUS |
106 | | -enviroment variable set to 1 (e.g. `export PYTESTUTILS_ALLOW_FOCUS=1`) to your execution environment to make this error |
107 | | -go away. |
108 | | -
|
109 | | -Thanks for using @focus! |
110 | | - """) |
0 commit comments