Skip to content

Commit 591967c

Browse files
committed
Backport pytest-runner fix from #633
1 parent 07d1a18 commit 591967c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

setup.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from os.path import isfile, join
1212
import re
1313
import logging
14+
import sys
1415
from setuptools import setup, find_packages
1516

1617
logging.basicConfig(level=logging.WARNING)
@@ -41,6 +42,14 @@
4142

4243
extras_require['test'] = tests_require
4344

45+
# Check for 'pytest-runner' only if setup.py was invoked with 'test'.
46+
# This optimizes setup.py for cases when pytest-runner is not needed,
47+
# using the approach that is suggested upstream.
48+
#
49+
# See https://pypi.org/project/pytest-runner/#conditional-requirement
50+
needs_pytest = {"pytest", "test", "ptr"}.intersection(sys.argv)
51+
pytest_runner = ["pytest-runner"] if needs_pytest else []
52+
4453

4554
setup(
4655
# Description
@@ -104,7 +113,7 @@
104113
'typing;python_version<"3.5"',
105114
'windows-curses;platform_system=="Windows"',
106115
],
107-
setup_requires=["pytest-runner"],
116+
setup_requires=pytest_runner,
108117
extras_require=extras_require,
109118
tests_require=tests_require
110119
)

0 commit comments

Comments
 (0)