diff --git a/pants.ini b/pants.ini index 52a1a3e08c4..a08f70cbae1 100644 --- a/pants.ini +++ b/pants.ini @@ -396,6 +396,7 @@ resolver_cache_dir: %(pants_bootstrapdir)s/python_cache/requirements [pytest] +version: pytest>=5.2.4 # TODO(#8651): We need this until we switch to implicit namespace packages so that pytest-cov # understands our __init__ files. NB: this version matches 3rdparty/python/requirements.txt. pytest_plugins: +["setuptools==40.6.3"] diff --git a/src/python/pants/backend/python/subsystems/pytest.py b/src/python/pants/backend/python/subsystems/pytest.py index e6531e45181..eecae40fdd7 100644 --- a/src/python/pants/backend/python/subsystems/pytest.py +++ b/src/python/pants/backend/python/subsystems/pytest.py @@ -3,6 +3,7 @@ from typing import List, Tuple +from pants.base.deprecated import deprecated_conditional from pants.subsystem.subsystem import Subsystem @@ -12,20 +13,25 @@ class PyTest(Subsystem): @classmethod def register_options(cls, register): super().register_options(register) - register('--version', default='pytest>=5.2.4', help="Requirement string for Pytest.") + register('--version', default='pytest>=4.6.6,<4.7', help="Requirement string for Pytest.") register( '--pytest-plugins', type=list, - default=['pytest-timeout>=1.3.3', 'pytest-cov>=2.8.1'], + default=[ + 'pytest-timeout>=1.3.3,<1.4', + 'pytest-cov>=2.8.1,<3', + "unittest2>=1.1.0 ; python_version<'3'", + "more-itertools<6.0.0 ; python_version<'3'", + ], help="Requirement strings for any plugins or additional requirements you'd like to use.", ) - register('--requirements', advanced=True, default='pytest>=5.2.4', + register('--requirements', advanced=True, default='pytest>=4.6.6,<4.7', help='Requirements string for the pytest library.', removal_version="1.25.0.dev0", removal_hint="Use --version instead.") - register('--timeout-requirements', advanced=True, default='pytest-timeout>=1.3.3', + register('--timeout-requirements', advanced=True, default='pytest-timeout>=1.3.3,<1.4', help='Requirements string for the pytest-timeout library.', removal_version="1.25.0.dev0", removal_hint="Use --pytest-plugins instead.") - register('--cov-requirements', advanced=True, default='pytest-cov>=2.8.1', + register('--cov-requirements', advanced=True, default='pytest-cov>=2.8.1,<3', help='Requirements string for the pytest-cov library.', removal_version="1.25.0.dev0", removal_hint="Use --pytest-plugins instead.") register('--unittest2-requirements', advanced=True, @@ -57,8 +63,22 @@ def format_opts(opt_symbol_names: List[str]) -> str: f"deprecated style: `{format_opts(configured_deprecated_option)}`.\nPlease use only one " f"approach (preferably the new approach of `--version` and `--pytest-plugins`)." ) + + deprecated_conditional( + lambda: opts.is_default("version") and opts.is_default("requirements"), + removal_version="1.25.0.dev2", + entity_description="Pants defaulting to a Python 2-compatible Pytest version", + hint_message="Pants will soon start defaulting to Pytest 5.x, which no longer supports " + "running tests with Python 2. In preparation for this change, you should " + "explicitly set what version of Pytest to use in your `pants.ini` under the " + "section `pytest`.\n\nIf you need to keep running tests with Python 2, set " + "`version` to `pytest>=4.6.6,<4.7` (the current default). If you don't have any " + "tests with Python 2 and want the newest Pytest, set `version` to " + "`pytest>=5.2.4`." + ) if configured_deprecated_option: return ( + "more-itertools<6.0.0 ; python_version<'3'", opts.requirements, opts.timeout_requirements, opts.cov_requirements,