MCPcopy
hub / github.com/django/django / find_top_level

Function find_top_level

django/test/runner.py:1165–1186  ·  view source on GitHub ↗
(top_level)

Source from the content-addressed store, hash-verified

1163
1164
1165def find_top_level(top_level):
1166 # Try to be a bit smarter than unittest about finding the default top-level
1167 # for a given directory path, to avoid breaking relative imports.
1168 # (Unittest's default is to set top-level equal to the path, which means
1169 # relative imports will result in "Attempted relative import in
1170 # non-package.").
1171
1172 # We'd be happy to skip this and require dotted module paths (which don't
1173 # cause this problem) instead of file paths (which do), but in the case of
1174 # a directory in the cwd, which would be equally valid if considered as a
1175 # top-level module or as a directory path, unittest unfortunately prefers
1176 # the latter.
1177 while True:
1178 init_py = os.path.join(top_level, "__init__.py")
1179 if not os.path.exists(init_py):
1180 break
1181 try_next = os.path.dirname(top_level)
1182 if try_next == top_level:
1183 # __init__.py all the way down? give up.
1184 break
1185 top_level = try_next
1186 return top_level
1187
1188
1189def _class_shuffle_key(cls):

Callers 1

load_tests_for_labelMethod · 0.85

Calls 2

joinMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…