Last active
August 29, 2015 14:04
-
-
Save nicoddemus/5458ca3fc5241cedaff3 to your computer and use it in GitHub Desktop.
How to embed `pytest.main` into a frozen executable created by cx_freeze
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest, sys | |
sys.exit(pytest.main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from cx_Freeze import setup, Executable | |
build_exe_options = {"includes": [ | |
'_pytest._argcomplete', | |
'_pytest._doctest', | |
'_pytest._pdb', | |
'_pytest._unittest', | |
'_pytest.capture', | |
'_pytest.config', | |
'_pytest.core', | |
'_pytest.genscript', | |
'_pytest.helpconfig', | |
'_pytest.hookspec', | |
'_pytest.junitxml', | |
'_pytest.main', | |
'_pytest.mark', | |
'_pytest.monkeypatch', | |
'_pytest.nose', | |
'_pytest.pastebin', | |
'_pytest.pytester', | |
'_pytest.python', | |
'_pytest.recwarn', | |
'_pytest.resultlog', | |
'_pytest.runner', | |
'_pytest.skipping', | |
'_pytest.standalonetemplate', | |
'_pytest.terminal', | |
'_pytest.tmpdir', | |
'py._builtin', | |
'py._path.local', | |
'py._io.capture', | |
'py._io.saferepr', | |
'py._iniconfig', | |
'py._io.terminalwriter', | |
'py._xmlgen', | |
'py._error', | |
'py._std', | |
# implicit std modules used by pytest | |
'argparse', | |
'shlex', | |
'warnings', | |
'types', | |
]} | |
setup( | |
name = "runtests", | |
version = "0.1", | |
description = "runtests", | |
executables = [Executable("runtests.py")], | |
options = {"build_exe": build_exe_options}, | |
) |
Seems like listing all packages in py
, _pytest
and a few standard library modules imported by pytest
internally does the trick.
Updated, still needs more testing:
from cx_Freeze import setup, Executable
build_exe_options = {"includes": [
'_pytest._argcomplete',
'_pytest._doctest',
'_pytest._pdb',
'_pytest._unittest',
'_pytest.capture',
'_pytest.config',
'_pytest.core',
'_pytest.genscript',
'_pytest.helpconfig',
'_pytest.hookspec',
'_pytest.junitxml',
'_pytest.main',
'_pytest.mark',
'_pytest.monkeypatch',
'_pytest.nose',
'_pytest.pastebin',
'_pytest.pytester',
'_pytest.python',
'_pytest.recwarn',
'_pytest.resultlog',
'_pytest.runner',
'_pytest.skipping',
'_pytest.standalonetemplate',
'_pytest.terminal',
'_pytest.tmpdir',
'py._builtin',
'py._path.local',
'py._io.capture',
'py._io.saferepr',
'py._iniconfig',
'py._io.terminalwriter',
'py._xmlgen',
'py._error',
'py._std',
'argparse',
'shlex',
'warnings',
'types',
]}
setup( name = "runtests",
version = "0.1",
description = "runtests",
executables = [Executable("runtests.py")],
options = {"build_exe": build_exe_options},
)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To test, install into a fresh virtual env:
And execute the generated executable with
--help
. This should yield a traceback like this: