From 1b0dbd8c406771530e6dbf42927774b65d40ba6a Mon Sep 17 00:00:00 2001 From: RedBeardCode Date: Sat, 25 Jun 2016 14:11:39 +0200 Subject: [PATCH] Move the freezing function from genscript.py to a new module freeze_support.py --- _pytest/config.py | 3 ++- _pytest/freeze_support.py | 45 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 _pytest/freeze_support.py diff --git a/_pytest/config.py b/_pytest/config.py index 8ed77c61d..463d8f04f 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -65,7 +65,8 @@ _preinit = [] default_plugins = ( "mark main terminal runner python pdb unittest capture skipping " "tmpdir monkeypatch recwarn pastebin helpconfig nose assertion " - "junitxml resultlog doctest cacheprovider setuponly setupplan").split() + "junitxml resultlog doctest cacheprovider freeze_support " + "setuponly setupplan").split() builtin_plugins = set(default_plugins) builtin_plugins.add("pytester") diff --git a/_pytest/freeze_support.py b/_pytest/freeze_support.py new file mode 100644 index 000000000..f78ccd298 --- /dev/null +++ b/_pytest/freeze_support.py @@ -0,0 +1,45 @@ +""" +Provides a function to report all internal modules for using freezing tools +pytest +""" + +def pytest_namespace(): + return {'freeze_includes': freeze_includes} + + +def freeze_includes(): + """ + Returns a list of module names used by py.test that should be + included by cx_freeze. + """ + import py + import _pytest + result = list(_iter_all_modules(py)) + result += list(_iter_all_modules(_pytest)) + return result + + +def _iter_all_modules(package, prefix=''): + """ + Iterates over the names of all modules that can be found in the given + package, recursively. + Example: + _iter_all_modules(_pytest) -> + ['_pytest.assertion.newinterpret', + '_pytest.capture', + '_pytest.core', + ... + ] + """ + import os + import pkgutil + if type(package) is not str: + path, prefix = package.__path__[0], package.__name__ + '.' + else: + path = package + for _, name, is_package in pkgutil.iter_modules([path]): + if is_package: + for m in _iter_all_modules(os.path.join(path, name), prefix=name + '.'): + yield prefix + m + else: + yield prefix + name \ No newline at end of file