@@ -699,37 +699,29 @@ and run it::
699
699
You'll see that the fixture finalizers could use the precise reporting
700
700
information.
701
701
702
- Integrating pytest runner and PyInstaller
703
- -----------------------------------------
702
+ Freezing pytest
703
+ ---------------
704
704
705
705
If you freeze your application using a tool like
706
706
`PyInstaller <https://pyinstaller.readthedocs.io >`_
707
707
in order to distribute it to your end-users, it is a good idea to also package
708
708
your test runner and run your tests using the frozen application. This way packaging
709
709
errors such as dependencies not being included into the executable can be detected early
710
710
while also allowing you to send test files to users so they can run them in their
711
- machines, which can be invaluable to obtain more information about a hard to reproduce bug.
711
+ machines, which can be useful to obtain more information about a hard to reproduce bug.
712
712
713
- Unfortunately ``PyInstaller `` can't discover them
714
- automatically because of ``pytest ``'s use of dynamic module loading, so you
715
- must declare them explicitly by using ``pytest.freeze_includes() `` and an
716
- auxiliary script:
713
+ Fortunately recent ``PyInstaller `` releases already have a custom hook
714
+ for pytest, but if you are using another tool to freeze executables
715
+ such as ``cx_freeze `` or ``py2exe ``, you can use ``pytest.freeze_includes() ``
716
+ to obtain the full list of internal pytest modules. How to configure the tools
717
+ to find the internal modules varies from tool to tool, however.
717
718
718
- .. code-block :: python
719
-
720
- # contents of create_executable.py
721
- import pytest
722
- import subprocess
719
+ Instead of freezing the pytest runner as a separate executable, you can make
720
+ your frozen program work as the pytest runner by some clever
721
+ argument handling during program startup. This allows you to
722
+ have a single executable, which is usually more convenient.
723
723
724
- hidden = []
725
- for x in pytest.freeze_includes():
726
- hidden.extend([' --hidden-import' , x])
727
- args = [' pyinstaller' ] + hidden + [' runtests_script.py' ]
728
- subprocess.check_call(' ' .join(args), shell = True )
729
-
730
- If you don't want to ship a different executable just in order to run your tests,
731
- you can make your program check for a certain flag and pass control
732
- over to ``pytest `` instead. For example::
724
+ .. code-block :: python
733
725
734
726
# contents of app_main.py
735
727
import sys
@@ -742,7 +734,7 @@ over to ``pytest`` instead. For example::
742
734
# by your argument-parsing library of choice as usual
743
735
...
744
736
745
- This makes it convenient to execute your tests from within your frozen
746
- application, using standard ``py.test `` command-line options::
737
+ This allows you to execute tests using the frozen
738
+ application with standard ``py.test `` command-line options::
747
739
748
740
./app_main --pytest --verbose --tb=long --junitxml=results.xml test-suite/
0 commit comments