Skip to content

Commit 05aba8b

Browse files
committed
Move the freezing function from genscript.py to a new module freeze_support.py
1 parent bba09f8 commit 05aba8b

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

_pytest/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class UsageError(Exception):
6565
default_plugins = (
6666
"mark main terminal runner python pdb unittest capture skipping "
6767
"tmpdir monkeypatch recwarn pastebin helpconfig nose assertion "
68-
"junitxml resultlog doctest cacheprovider").split()
68+
"junitxml resultlog doctest cacheprovider freeze_support").split()
6969

7070
builtin_plugins = set(default_plugins)
7171
builtin_plugins.add("pytester")

_pytest/freeze_support.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""
2+
Provides a function to report all internal modules for using freezing tools
3+
pytest
4+
"""
5+
6+
def pytest_namespace():
7+
return {'freeze_includes': freeze_includes}
8+
9+
10+
def freeze_includes():
11+
"""
12+
Returns a list of module names used by py.test that should be
13+
included by cx_freeze.
14+
"""
15+
import py
16+
import _pytest
17+
result = list(_iter_all_modules(py))
18+
result += list(_iter_all_modules(_pytest))
19+
return result
20+
21+
22+
def _iter_all_modules(package, prefix=''):
23+
"""
24+
Iterates over the names of all modules that can be found in the given
25+
package, recursively.
26+
Example:
27+
_iter_all_modules(_pytest) ->
28+
['_pytest.assertion.newinterpret',
29+
'_pytest.capture',
30+
'_pytest.core',
31+
...
32+
]
33+
"""
34+
import os
35+
import pkgutil
36+
if type(package) is not str:
37+
path, prefix = package.__path__[0], package.__name__ + '.'
38+
else:
39+
path = package
40+
for _, name, is_package in pkgutil.iter_modules([path]):
41+
if is_package:
42+
for m in _iter_all_modules(os.path.join(path, name), prefix=name + '.'):
43+
yield prefix + m
44+
else:
45+
yield prefix + name

0 commit comments

Comments
 (0)