From ca7f1e64f80286e73d93451ee3b09fa8d4cce249 Mon Sep 17 00:00:00 2001 From: Brian Thorne Date: Tue, 23 Jul 2019 21:50:56 +1000 Subject: [PATCH] Backport pytest-runner fix from #633 --- setup.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c600b7215..27121b61a 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) @@ -41,6 +42,14 @@ 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 @@ -104,7 +113,7 @@ 'typing;python_version<"3.5"', 'windows-curses;platform_system=="Windows"', ], - setup_requires=["pytest-runner"], + setup_requires=pytest_runner, extras_require=extras_require, tests_require=tests_require )