From 80710795c0721ae86c91ddaeacdc8e75caba55f9 Mon Sep 17 00:00:00 2001 From: Pierre-Jean Texier Date: Sat, 29 Jun 2019 21:19:08 +0200 Subject: [PATCH] setup.py: require pytest-runner only when necessary This optimizes setup.py for cases when pytest-runner is not needed, using the approach that is suggested upstream: https://pypi.python.org/pypi/pytest-runner#conditional-requirement --- setup.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 221c0301d..ded73f458 100644 --- a/setup.py +++ b/setup.py @@ -11,6 +11,7 @@ from os.path import isfile, join import re import logging +import sys from setuptools import setup, find_packages logging.basicConfig(level=logging.WARNING) @@ -40,6 +41,13 @@ extras_require["test"] = tests_require +# Check for 'pytest-runner' only if setup.py was invoked with 'test'. +# This optimizes setup.py for cases when pytest-runner is not needed, +# using the approach that is suggested upstream. +# +# See https://pypi.org/project/pytest-runner/#conditional-requirement +needs_pytest = {"pytest", "test", "ptr"}.intersection(sys.argv) +pytest_runner = ["pytest-runner"] if needs_pytest else [] setup( # Description @@ -96,7 +104,7 @@ 'windows-curses;platform_system=="Windows"', "filelock", ], - setup_requires=["pytest-runner"], + setup_requires=pytest_runner, extras_require=extras_require, tests_require=tests_require, )