Skip to content

Commit

Permalink
Only set the default versions to Pytest 4.6, but deprecate default arg
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Arellano committed Nov 20, 2019
1 parent e3a1625 commit a8c4f88
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions pants.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
30 changes: 25 additions & 5 deletions src/python/pants/backend/python/subsystems/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from typing import List, Tuple

from pants.base.deprecated import deprecated_conditional
from pants.subsystem.subsystem import Subsystem


Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a8c4f88

Please sign in to comment.