Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump default Pytest to 4.6 and add warning for future change to Pytest 5 #8648

Merged
merged 6 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pants.ini
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,13 @@ interpreter_cache_dir: %(pants_bootstrapdir)s/python_cache/interpreters
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"]


[test.pytest]
fast: false
chroot: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_passing_test(self):

pants/dummies/test_pass.py . [100%]

=========================== 1 passed in SOME_TEXT ===========================
============================== 1 passed in SOME_TEXT ===============================


testprojects/tests/python/pants/dummies:passing_target ..... SUCCESS
Expand Down Expand Up @@ -98,7 +98,7 @@ def test_fail():
E assert False

pants/dummies/test_fail.py:2: AssertionError
=========================== 1 failed in SOME_TEXT ===========================
============================== 1 failed in SOME_TEXT ===============================


testprojects/tests/python/pants/dummies:failing_target ..... FAILURE
Expand Down Expand Up @@ -130,7 +130,7 @@ def test_fail():
E assert False

pants/dummies/test_fail.py:2: AssertionError
=========================== 1 failed in SOME_TEXT ===========================
============================== 1 failed in SOME_TEXT ===============================

testprojects/tests/python/pants/dummies:passing_target stdout:
============================= test session starts ==============================
Expand All @@ -141,7 +141,7 @@ def test_fail():

pants/dummies/test_pass.py . [100%]

=========================== 1 passed in SOME_TEXT ===========================
============================== 1 passed in SOME_TEXT ===============================


testprojects/tests/python/pants/dummies:failing_target ..... FAILURE
Expand All @@ -165,7 +165,7 @@ def test_source_dep_absolute_import(self):

pants/dummies/test_with_source_dep_absolute_import.py . [100%]

=========================== 1 passed in SOME_TEXT ===========================
============================== 1 passed in SOME_TEXT ===============================


testprojects/tests/python/pants/dummies:target_with_source_dep_absolute_import ..... SUCCESS
Expand All @@ -188,7 +188,7 @@ def test_source_dep_relative_import(self):

pants/dummies/test_with_source_dep_relative_import.py . [100%]

=========================== 1 passed in SOME_TEXT ===========================
============================== 1 passed in SOME_TEXT ===============================


testprojects/tests/python/pants/dummies:target_with_source_dep_relative_import ..... SUCCESS
Expand All @@ -211,7 +211,7 @@ def test_thirdparty_dep(self):

pants/dummies/test_with_thirdparty_dep.py . [100%]

=========================== 1 passed in SOME_TEXT ===========================
============================== 1 passed in SOME_TEXT ===============================


testprojects/tests/python/pants/dummies:target_with_thirdparty_dep ..... SUCCESS
Expand All @@ -234,7 +234,7 @@ def test_transitive_dep(self):

pants/dummies/test_with_transitive_dep.py . [100%]

=========================== 1 passed in SOME_TEXT ===========================
============================== 1 passed in SOME_TEXT ===============================


testprojects/tests/python/pants/dummies:target_with_transitive_dep ..... SUCCESS
Expand Down
37 changes: 24 additions & 13 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,28 +13,29 @@ class PyTest(Subsystem):
@classmethod
def register_options(cls, register):
super().register_options(register)
register('--version', default='pytest>=3.0.7,<3.7', 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.2,<1.3',
'pytest-cov>=2.4,<2.5',
"unittest2>=0.6.0,<=1.9.0 ; python_version<'3'"
'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>=3.0.7,<3.7',
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.2,<1.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.4,<2.5',
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,
default="unittest2>=0.6.0,<=1.9.0 ; python_version<'3'",
default="unittest2>=1.1.0 ; python_version<'3'",
help='Requirements string for the unittest2 library, which some python versions '
'may need.',
removal_version="1.25.0.dev0", removal_hint="Use --pytest-plugins instead.")
Expand Down Expand Up @@ -61,6 +63,19 @@ 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'",
Expand All @@ -69,8 +84,4 @@ def format_opts(opt_symbol_names: List[str]) -> str:
opts.cov_requirements,
opts.unittest2_requirements,
)
return (
"more-itertools<6.0.0 ; python_version<'3'",
opts.version,
*opts.pytest_plugins
)
return (opts.version, *opts.pytest_plugins)
6 changes: 4 additions & 2 deletions src/python/pants/testutil/base/context_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ class DummyWorkUnit:
"""

def output(self, name):
return sys.stderr
return sys.stderr.buffer

def set_outcome(self, outcome):
return sys.stderr.write('\nWorkUnit outcome: {}\n'.format(WorkUnit.outcome_string(outcome)))
return sys.stderr.buffer.write(
f'\nWorkUnit outcome: {WorkUnit.outcome_string(outcome)}\n'.encode()
)

class DummyRunTracker:
"""A runtracker stand-in that does no actual tracking."""
Expand Down
2 changes: 1 addition & 1 deletion testprojects/tests/python/pants/dummies/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ python_tests(
name = 'target_with_thirdparty_dep',
sources = ['test_with_thirdparty_dep.py'],
dependencies = [
'3rdparty/python:ansicolors',
'3rdparty/python:typing-extensions',
],
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from colors import red, strip_color
from typing_extensions import Literal


def test_f():
assert strip_color(red("foo")) == "foo"
assert Literal[1] == Literal[1]
assert Literal[1] != Literal[2]
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ def test_pants_test_interpreter_selection_with_pexrc(self):
'python-setup': {
'interpreter_cache_dir': interpreters_cache,
'interpreter_search_paths': ['<PEXRC>'],
},
# NB: we pin Pytest to 4.6 to ensure Pytest still works with Python 2.
'pytest': {
'version': 'pytest==4.6.6',
}
}
pants_run_27 = self.run_pants(
Expand All @@ -167,6 +171,10 @@ def test_pants_test_interpreter_selection_with_option_2(self):
'python-setup': {
'interpreter_constraints': ['CPython>=2.7,<4'],
'interpreter_cache_dir': interpreters_cache,
},
# NB: we pin Pytest to 4.6 to ensure Pytest still works with Python 2.
'pytest': {
'version': 'pytest==4.6.6',
}
}
pants_run_2 = self.run_pants(
Expand Down