Skip to content

Commit ae9d3bf

Browse files
committed
Freeze docs: PyInstaller hook and wording
As discussed during the review, suggest in general to use PyInstaller and just mention pytest.freeze_includes() in less detail on how to actually use it, because it varies from tool to tool.
1 parent ed36d62 commit ae9d3bf

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

doc/en/example/simple.rst

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -699,37 +699,29 @@ and run it::
699699
You'll see that the fixture finalizers could use the precise reporting
700700
information.
701701

702-
Integrating pytest runner and PyInstaller
703-
-----------------------------------------
702+
Freezing pytest
703+
---------------
704704

705705
If you freeze your application using a tool like
706706
`PyInstaller <https://pyinstaller.readthedocs.io>`_
707707
in order to distribute it to your end-users, it is a good idea to also package
708708
your test runner and run your tests using the frozen application. This way packaging
709709
errors such as dependencies not being included into the executable can be detected early
710710
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.
712712

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.
717718

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.
723723

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
733725
734726
# contents of app_main.py
735727
import sys
@@ -742,7 +734,7 @@ over to ``pytest`` instead. For example::
742734
# by your argument-parsing library of choice as usual
743735
...
744736
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::
747739

748740
./app_main --pytest --verbose --tb=long --junitxml=results.xml test-suite/

0 commit comments

Comments
 (0)