I saw that #11511 is closed, to I tried it out, trying to package tests into a frozen app. Unfortunately, I now get
ERROR: module or package not found: myapp.test (missing __init__.py?)
pytest 9.1.1 with pyinstaller 6.21.0 on Windows 11.
MWE:
myapp\test\test_example.py
def test_example():
assert 1 + 1 == 2
myapp\test_init_.py
myapp_init_.py
main.py
import sys
import pytest
if __name__ == "__main__":
sys.exit(
pytest.main(
["-o", "consider_namespace_packages=true", "--pyargs", "myapp.test"],
)
)
myapp.spec
from PyInstaller.building.api import COLLECT, EXE, PYZ
from PyInstaller.building.build_main import Analysis
from PyInstaller.utils.hooks import collect_submodules
a = Analysis(
["main.py"],
hiddenimports=["myapp", "myapp.test", *collect_submodules("myapp.test"), "pytest"],
)
pyz = PYZ(a.pure)
exe = EXE(pyz, a.scripts, [], name="myapp")
coll = COLLECT(exe, a.binaries, a.datas, name="myapp")
pyproject.toml
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "myapp"
version = "0.1.0"
[tool.pytest.ini_options]
consider_namespace_packages = true
run.bat
@echo off
pytest
python main.py
pyinstaller myapp.spec --clean -y
dist\myapp\myapp.exe
I saw that #11511 is closed, to I tried it out, trying to package tests into a frozen app. Unfortunately, I now get
pytest9.1.1 withpyinstaller6.21.0 on Windows 11.MWE:
myapp\test\test_example.py
myapp\test_init_.py
myapp_init_.py
main.py
myapp.spec
pyproject.toml
run.bat