Open bersbersbers opened 1 year ago
this is most likely related to finding the import path
whats the result if importlib searching the module in the frozen executable
ps https://github.com/pytest-dev/pytest/blob/cdddd6d69533c07092c64445a0d42d1fc75c8299/src/_pytest/main.py#L849-L913 implements the logic for the case
whats the result if importlib searching the module in the frozen executable
I added
module_name = "folder"
spec = importlib.util.find_spec(module_name)
print(spec)
print(spec.origin is None)
to my code, and this is what I get:
ModuleSpec(name='folder', loader=<_frozen_importlib_external.NamespaceLoader object at 0x000002329F3B1A90>, submodule_search_locations=_NamespacePath(['C:\\Users\\bers\\AppData\\Local\\Temp\\_MEI121682\\folder']))
True
So spec.origin
is None
.
By the way, what works is (also) including test files as data, using --add-data folder/test_file.py;folder
and then calling something like sys.exit(pytest.main(Path(__file__).parent / "folder"))
. But that looks like a nasty workaround to me, since PyInstaller
already needs to include test_file.py
as code to follow all dependencies, and then needs to include it another time as data.
my understanding is, that pytest currently has no collector able to load test modules from frozen pyinstaller stuff
pytest currently has no collector able to load test modules from frozen pyinstaller stuff
Having looked at the collection a bit now, I think I agree. Everything looks pretty much Path
-based, which I understand "pyinstaller stuff" is not.
So at least I didn't file an issue that has an RTFM-kind of answer 😉
I am having trouble with
--pyargs
test discovery in a frozen application. I am using Windows 10 22H2, pytest 7.4.2, pyinstaller 6.1.0.Minimal example
app.py
folder\test_file.py
run.bat
Output:
Since
import
works, I guess that this is not primarily apyinstaller
issue, but do let me know if you think it is :)