Skip to content

Write a unit test that builds a simple pygame program with pyinstaller, then runs that application - to eventually run on CI (2136) #1125

Open
@GalacticEmperor1

Description

@GalacticEmperor1

Issue №2136 opened by illume at 2020-10-04 11:14:08

Now that pyinstaller has per package hooks, it makes sense to test it ourselves.

  • Have a tests/pyinstaller_test.py which
    • creates an executable with pyinstaller ([see this test case](Fix pyinstaller issues with pygame.font.Font pygame/pygame#2133 pullrequestreview-501547013), but a an example which uses quite a bit of functionality and perhaps reuses the example code would be best)
    • runs the executable, and asserts on the return code
    • skips the test if pyinstaller is not installed, not fails it. (pyinstaller should be an optional dependency).
  • We'd need to add a python -m pip install pyinstaller to each of the CI jobs we want to test it on.

Comments

# # ankith26 commented at 2020-10-04 13:26:10

I found a useful link (I havent done much research myself, but the link looks useful for this case):
https://github.com/pyinstaller/hooksample

Continuing from my last message in the PR linked, let me clearly explain this time.

Here is how I would launch the "aliens" example that comes with pygame.

import pygame.examples.aliens
pygame.examples.aliens.main()

I save this bit of code into a python file, and when I run it, it loads the nice game.

Now I use pyinstaller on this file, and when I run the exe, it crashes.
This crash is intentional, you can try it out.

This is happenning because pyinstaller has not bundled any data files needed by aliens to work.
Neither will any other examples work if they are used this way.

Now for tests/pyinstaller_test.py, it means that the test code we are writing must not rely on any external resource, because pyinstaller is not going to bundle it automatically for us.
If it does rely on any image/font/audio file, then we would have to write a spec file for it


# # illume commented at 2022-01-22 21:10:35

I guess there could be a way to hunt data files. If not, then specify them.


# # illume commented at 2022-01-22 21:14:13

I guess there are examples without data files where we could start.

It would be handy to be able to quit the examples via environment variable. Otherwise perhaps one of the command line examples would be fine for this pyinstaller test… because they should exit with a suitable return code that can be checked.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions