(path)
| 343 | # To make test names independent of the CONFTEST_LOAD_POLICY value replace path by module name if possible. |
| 344 | @lazy |
| 345 | def _unify_path(path): |
| 346 | py_ext = ".py" |
| 347 | |
| 348 | path = path.strip() |
| 349 | if _conftest_load_policy_is_local(path) and path.endswith(py_ext): |
| 350 | # Try to find best match for path as a module among test modules and use it as a class name. |
| 351 | # This is the only way to unify different CONFTEST_LOAD_POLICY modes |
| 352 | suff_tree = _suffix_test_modules_tree() |
| 353 | node, res = suff_tree, [] |
| 354 | |
| 355 | assert path.endswith(py_ext), path |
| 356 | parts = path[: -len(py_ext)].split(SEP) |
| 357 | |
| 358 | # Use SEP as trailing terminator to make an extra step |
| 359 | # and find a proper match when parts is a full matching path |
| 360 | for p in reversed([SEP] + parts): |
| 361 | if p in node: |
| 362 | node = node[p] |
| 363 | res.append(p) |
| 364 | else: |
| 365 | if res: |
| 366 | return '.'.join(reversed(res)) + py_ext |
| 367 | else: |
| 368 | # Top level test module |
| 369 | if TEST_MOD_PREFIX + p in sys.extra_modules: |
| 370 | return p + py_ext |
| 371 | # Unknown module - raise an error |
| 372 | break |
| 373 | |
| 374 | raise MissingTestModule("Can't find proper module for '{}' path among: {}".format(path, suff_tree)) |
| 375 | else: |
| 376 | return path |
| 377 | |
| 378 | |
| 379 | def colorize_pytest_error(text): |
no test coverage detected