Hi everyone, I'm having trouble getting "pytest.main()" to run inside a frozen script created by cx_freeze (12-line source code here: https://gist.github.com/nicoddemus/5458ca3fc5241cedaff3); when I run the generated executable (I'm on windows), I get this exception: Traceback (most recent call last): File "X:\pytest_cx_freeze\.env27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module> exec(code, m.__dict__) File "runtests.py", line 1, in <module> import pytest, sys File "X:\pytest_cx_freeze\.env27\lib\site-packages\pytest.py", line 14, in <module> from _pytest.config import main, UsageError, _preloadplugins, cmdline File "X:\pytest_cx_freeze\.env27\lib\site-packages\_pytest\config.py", line 398, in <module> class MyOptionParser(py.std.argparse.ArgumentParser): File "X:\pytest_cx_freeze\.env27\lib\site-packages\py\_apipkg.py", line 124, in __makeattr result = importobj(modpath, attrname) File "X:\pytest_cx_freeze\.env27\lib\site-packages\py\_apipkg.py", line 47, in importobj module = __import__(modpath, None, None, ['__doc__']) ImportError: No module named _std I have tried to explicitly import "py._std" on my script, but it also fails: File "X:\pytest_cx_freeze\.env27\lib\site-packages\_pytest\config.py", line 398, in <module> class MyOptionParser(py.std.argparse.ArgumentParser): File "X:\pytest_cx_freeze\.env27\lib\site-packages\py\_std.py", line 15, in __getattr__ raise AttributeError("py.std: could not import %s" % name) AttributeError: py.std: could not import argparse Looks like py's lazy import machinery can't be tracked by cx_freeze. A google search didn't reveal anything useful so for far, unfortunately. Any thoughts? Long story for those interested: we package our desktop applications as executables for both windows and linux using cx_freeze. Traditionally, we also pack the test runner into the executable in order to run the test suite using the packed code, with the test runner being activated by a `--selftest` flag. This ensures everything the application needs to run is correctly packed into the executable, and also enables us to write test scripts and hand them over to customers to run on their site in order to track a bug or to test something out. Best Regards, Bruno.
Hi Bruno, i think there are two ways to solve this: - find out how to make py.std work with cx_freeze (haven't looked at that myself yet) - eliminate use of py.std in pytest and maybe py. Personally, I am fine with a PR on that, probably quite straightforward to do. best, Holger On Wed, Jul 23, 2014 at 19:52 -0300, Bruno Oliveira wrote:
Hi everyone,
I'm having trouble getting "pytest.main()" to run inside a frozen script created by cx_freeze (12-line source code here: https://gist.github.com/nicoddemus/5458ca3fc5241cedaff3); when I run the generated executable (I'm on windows), I get this exception:
Traceback (most recent call last): File "X:\pytest_cx_freeze\.env27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module> exec(code, m.__dict__) File "runtests.py", line 1, in <module> import pytest, sys File "X:\pytest_cx_freeze\.env27\lib\site-packages\pytest.py", line 14, in <module> from _pytest.config import main, UsageError, _preloadplugins, cmdline File "X:\pytest_cx_freeze\.env27\lib\site-packages\_pytest\config.py", line 398, in <module> class MyOptionParser(py.std.argparse.ArgumentParser): File "X:\pytest_cx_freeze\.env27\lib\site-packages\py\_apipkg.py", line 124, in __makeattr result = importobj(modpath, attrname) File "X:\pytest_cx_freeze\.env27\lib\site-packages\py\_apipkg.py", line 47, in importobj module = __import__(modpath, None, None, ['__doc__']) ImportError: No module named _std
I have tried to explicitly import "py._std" on my script, but it also fails:
File "X:\pytest_cx_freeze\.env27\lib\site-packages\_pytest\config.py", line 398, in <module> class MyOptionParser(py.std.argparse.ArgumentParser): File "X:\pytest_cx_freeze\.env27\lib\site-packages\py\_std.py", line 15, in __getattr__ raise AttributeError("py.std: could not import %s" % name) AttributeError: py.std: could not import argparse
Looks like py's lazy import machinery can't be tracked by cx_freeze.
A google search didn't reveal anything useful so for far, unfortunately. Any thoughts?
Long story for those interested: we package our desktop applications as executables for both windows and linux using cx_freeze. Traditionally, we also pack the test runner into the executable in order to run the test suite using the packed code, with the test runner being activated by a `--selftest` flag. This ensures everything the application needs to run is correctly packed into the executable, and also enables us to write test scripts and hand them over to customers to run on their site in order to track a bug or to test something out.
Best Regards, Bruno.
_______________________________________________ Pytest-dev mailing list Pytest-dev@python.org https://mail.python.org/mailman/listinfo/pytest-dev
Hi Holger, On Thu, Jul 24, 2014 at 11:36 AM, holger krekel <holger@merlinux.eu> wrote:
i think there are two ways to solve this:
- find out how to make py.std work with cx_freeze (haven't looked at that myself yet)
I'm investigating this and will share any findings. - eliminate use of py.std in pytest and maybe py.
Personally, I am fine with a PR on that, probably quite straightforward to do.
Didn't know that could be an option; I will take a look into it, shouldn't be too complicated. Thanks for the answer! Bruno
Hi all, I managed to get it to work by explicitly importing pytest and py modules explicitly. The version that worked for me is in the same gist link I sent earlier (https://gist.github.com/nicoddemus/5458ca3fc5241cedaff3), which I made public so others that run into the same problem can find it. Also created a PR that eliminates py.std use from pytest, although I could get the frozen executable to work without needing that after all. Just went ahead with the PR because Holger showed interest on it. :) Cheers, On Thu, Jul 24, 2014 at 12:24 PM, Bruno Oliveira <nicoddemus@gmail.com> wrote:
Hi Holger,
On Thu, Jul 24, 2014 at 11:36 AM, holger krekel <holger@merlinux.eu> wrote:
i think there are two ways to solve this:
- find out how to make py.std work with cx_freeze (haven't looked at that myself yet)
I'm investigating this and will share any findings.
- eliminate use of py.std in pytest and maybe py.
Personally, I am fine with a PR on that, probably quite straightforward to do.
Didn't know that could be an option; I will take a look into it, shouldn't be too complicated.
Thanks for the answer!
Bruno
Hi all, For future reference, I created a repository with a solution at https://github.com/nicoddemus/cx_freeze_pytest_example. Cheers, On Sun, Jul 27, 2014 at 12:57 AM, Bruno Oliveira <nicoddemus@gmail.com> wrote:
Hi all,
I managed to get it to work by explicitly importing pytest and py modules explicitly. The version that worked for me is in the same gist link I sent earlier (https://gist.github.com/nicoddemus/5458ca3fc5241cedaff3), which I made public so others that run into the same problem can find it.
Also created a PR that eliminates py.std use from pytest, although I could get the frozen executable to work without needing that after all. Just went ahead with the PR because Holger showed interest on it. :)
Cheers,
On Thu, Jul 24, 2014 at 12:24 PM, Bruno Oliveira <nicoddemus@gmail.com> wrote:
Hi Holger,
On Thu, Jul 24, 2014 at 11:36 AM, holger krekel <holger@merlinux.eu> wrote:
i think there are two ways to solve this:
- find out how to make py.std work with cx_freeze (haven't looked at that myself yet)
I'm investigating this and will share any findings.
- eliminate use of py.std in pytest and maybe py.
Personally, I am fine with a PR on that, probably quite straightforward to do.
Didn't know that could be an option; I will take a look into it, shouldn't be too complicated.
Thanks for the answer!
Bruno
participants (2)
-
Bruno Oliveira -
holger krekel