Skip to content

Commit ecc0d68

Browse files
committed
Don't assume pytest executable is called py.test in unit tests
Many distributions append suffixes to installed Python script names to differentiate between Python 2 and 3 versions. For example, Debian installs the Python 3 pytest binary as `py.test-3` (see https://packages.debian.org/stretch/all/python3-pytest/filelist). In the unit tests, invoke the pytest binary using `sys.exectuable` to make sure that the subprocesses run with the same version of Python as the unit tests themselves.
1 parent 7a64a1f commit ecc0d68

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

tests/test_pytest_mpl.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ def test_fails(tmpdir):
8686
f.write(TEST_FAILING)
8787

8888
# If we use --mpl, it should detect that the figure is wrong
89-
code = subprocess.call('py.test --mpl {0}'.format(test_file), shell=True)
89+
code = subprocess.call('{0} -m pytest --mpl {1}'.format(sys.executable, test_file), shell=True)
9090
assert code != 0
9191

9292
# If we don't use --mpl option, the test should succeed
93-
code = subprocess.call('py.test {0}'.format(test_file), shell=True)
93+
code = subprocess.call('{0} -m pytest {1}'.format(sys.executable, test_file), shell=True)
9494
assert code == 0
9595

9696

@@ -113,7 +113,7 @@ def test_output_dir(tmpdir):
113113

114114
# When we run the test, we should get output images where we specify
115115
output_dir = tmpdir.join('test_output_dir').strpath
116-
code = subprocess.call('py.test --mpl-results-path={0} --mpl {1}'.format(output_dir, test_file),
116+
code = subprocess.call('{0} -m pytest --mpl-results-path={1} --mpl {2}'.format(sys.executable, output_dir, test_file),
117117
shell=True)
118118

119119
assert code != 0
@@ -150,13 +150,13 @@ def test_generate(tmpdir):
150150
gen_dir = tmpdir.mkdir('spam').mkdir('egg').strpath
151151

152152
# If we don't generate, the test will fail
153-
p = subprocess.Popen('py.test --mpl {0}'.format(test_file), shell=True,
153+
p = subprocess.Popen('{0} -m pytest --mpl {1}'.format(sys.executable, test_file), shell=True,
154154
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
155155
p.wait()
156156
assert b'Image file not found for comparison test' in p.stdout.read()
157157

158158
# If we do generate, the test should succeed and a new file will appear
159-
code = subprocess.call('py.test --mpl-generate-path={0} {1}'.format(gen_dir, test_file), shell=True)
159+
code = subprocess.call('{0} -m pytest --mpl-generate-path={1} {2}'.format(sys.executable, gen_dir, test_file), shell=True)
160160
assert code == 0
161161
assert os.path.exists(os.path.join(gen_dir, 'test_gen.png'))
162162

0 commit comments

Comments
 (0)