Skip to content

Commit 48e6331

Browse files
tests/conftest.py: automatically install packages required for testing.
In top-level scope, we now run `pip install` command to install required packages. This is probably badly mis-using pytest's conftest.py, but it seems to be the only way to programatically install packages when pytest is run directly.
1 parent 333bc18 commit 48e6331

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

tests/conftest.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,40 @@
11
import copy
22
import os
33
import platform
4+
import subprocess
45
import sys
56

7+
import pytest
8+
9+
# Install required packages. There doesn't seem to be any official way for
10+
# us to programmatically specify required test packages in setup.py, or in
11+
# pytest. Doing it here seems to be the least ugly approach.
12+
#
13+
# However our diagnostics do not show up so this can cause an unfortunate pause
14+
# before tests start to run.
15+
#
16+
def install_required_packages():
17+
packages = 'pytest fontTools pymupdf-fonts flake8 pylint codespell'
18+
if platform.system() == 'Windows' and int.bit_length(sys.maxsize+1) == 32:
19+
# No pillow wheel available, and doesn't build easily.
20+
pass
21+
else:
22+
packages += ' pillow'
23+
if platform.system().startswith('MSYS_NT-'):
24+
# psutil not available on msys2.
25+
pass
26+
else:
27+
packages += ' psutil'
28+
command = f'pip install --upgrade {packages}'
29+
print(f'{__file__}:install_required_packages)(): Running: {command}', flush=1)
30+
subprocess.run(command, shell=1, check=1)
31+
32+
install_required_packages()
33+
34+
# Need to import pymupdf only after we've installed pymupdf-fonts above,
35+
# because pymupdf imports pymupdf_fonts, and copes with import failure.
636
import pymupdf
737

8-
import pytest
938

1039
PYMUPDF_PYTEST_RESUME = os.environ.get('PYMUPDF_PYTEST_RESUME')
1140

0 commit comments

Comments
 (0)