test_pyinstaller.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import subprocess
  2. from pathlib import Path
  3. import pytest
  4. # PyInstaller has been very unproactive about replacing 'imp' with 'importlib'.
  5. @pytest.mark.filterwarnings('ignore::DeprecationWarning')
  6. # It also leaks io.BytesIO()s.
  7. @pytest.mark.filterwarnings('ignore::ResourceWarning')
  8. @pytest.mark.parametrize("mode", ["--onedir", "--onefile"])
  9. @pytest.mark.slow
  10. def test_pyinstaller(mode, tmp_path):
  11. """Compile and run pyinstaller-smoke.py using PyInstaller."""
  12. pyinstaller_cli = pytest.importorskip("PyInstaller.__main__").run
  13. source = Path(__file__).with_name("pyinstaller-smoke.py").resolve()
  14. args = [
  15. # Place all generated files in ``tmp_path``.
  16. '--workpath', str(tmp_path / "build"),
  17. '--distpath', str(tmp_path / "dist"),
  18. '--specpath', str(tmp_path),
  19. mode,
  20. str(source),
  21. ]
  22. pyinstaller_cli(args)
  23. if mode == "--onefile":
  24. exe = tmp_path / "dist" / source.stem
  25. else:
  26. exe = tmp_path / "dist" / source.stem / source.stem
  27. p = subprocess.run([str(exe)], check=True, stdout=subprocess.PIPE)
  28. assert p.stdout.strip() == b"I made it!"