Args: append_path: optional path to append to the tests dir path Return: The full path to the `tests` dir, so that the tests can be invoked from anywhere. Optionally `append_path` is joined after the `tests` dir the former is provided.
(append_path=None)
| 133 | |
| 134 | |
| 135 | def get_tests_dir(append_path=None): |
| 136 | """ |
| 137 | Args: |
| 138 | append_path: optional path to append to the tests dir path |
| 139 | Return: |
| 140 | The full path to the `tests` dir, so that the tests can be invoked from anywhere. Optionally `append_path` is |
| 141 | joined after the `tests` dir the former is provided. |
| 142 | """ |
| 143 | # this function caller's __file__ |
| 144 | caller__file__ = inspect.stack()[1][1] |
| 145 | tests_dir = os.path.abspath(os.path.dirname(caller__file__)) |
| 146 | |
| 147 | while not tests_dir.endswith("tests"): |
| 148 | tests_dir = os.path.dirname(tests_dir) |
| 149 | |
| 150 | if append_path: |
| 151 | return Path(tests_dir, append_path).as_posix() |
| 152 | else: |
| 153 | return tests_dir |
| 154 | |
| 155 | |
| 156 | # Taken from the following PR: |
no outgoing calls
no test coverage detected