Skip to content

Commit c75e272

Browse files
authored
Revert "Deprecate colcon_core.task.python.test.has_test_dependency()" (#548)
It turns out that this mechanism is used to communicate the Python-type dependencies from the setuptools options when processing ament_python packages, which otherwise have ROS-type dependencies. So while we're seeing `python3-pytest` in the test dependency list, the pure python code here looks for the pure python dependency `pytest`. Since this doesn't actually save us much time and is clearly still needed, I'll take the same approach in the Python project code as was taken in ament_python so that we can all use the same Python testing task. This reverts commit 300f841.
1 parent a6c04e0 commit c75e272

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

colcon_core/task/python/test/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import re
55
import traceback
6-
import warnings
76

87
from colcon_core.entry_point import load_entry_points
98
from colcon_core.logging import colcon_logger
@@ -218,10 +217,6 @@ def has_test_dependency(setup_py_data, name):
218217
False otherwise
219218
:rtype: bool
220219
"""
221-
warnings.warn(
222-
"'colcon_core.task.python.test.has_test_dependency()' "
223-
"has been deprecated, use dependencies['test'] from the "
224-
'associated package descriptor instead', stacklevel=2)
225220
tests_require = extract_dependencies(setup_py_data).get('test')
226221
for d in tests_require or []:
227222
# the name might be followed by a version

colcon_core/task/python/test/pytest.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from colcon_core.plugin_system import satisfies_version
1111
from colcon_core.plugin_system import SkipExtensionException
1212
from colcon_core.task import run
13+
from colcon_core.task.python.test import has_test_dependency
1314
from colcon_core.task.python.test import PythonTestingStepExtensionPoint
1415
from colcon_core.verb.test import logger
1516
from pkg_resources import parse_version
@@ -46,8 +47,7 @@ def add_arguments(self, *, parser): # noqa: D102
4647
help='Generate coverage information')
4748

4849
def match(self, context, env, setup_py_data): # noqa: D102
49-
test_deps = context.pkg.dependencies.get('test') or set()
50-
return 'pytest' in test_deps
50+
return has_test_dependency(setup_py_data, 'pytest')
5151

5252
async def step(self, context, env, setup_py_data): # noqa: D102
5353
cmd = [sys.executable, '-m', 'pytest']
@@ -71,10 +71,9 @@ async def step(self, context, env, setup_py_data): # noqa: D102
7171
]
7272
env = dict(env)
7373

74-
test_deps = context.pkg.dependencies.get('test') or set()
7574
if (
7675
context.args.pytest_with_coverage or
77-
'pytest-cov' in test_deps
76+
has_test_dependency(setup_py_data, 'pytest-cov')
7877
):
7978
try:
8079
from pytest_cov import __version__ as pytest_cov_version
Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright 2021 Open Source Robotics Foundation, Inc.
22
# Licensed under the Apache License, Version 2.0
33

4-
from colcon_core.dependency_descriptor import DependencyDescriptor
54
from colcon_core.package_descriptor import PackageDescriptor
65
from colcon_core.task import TaskContext
76
from colcon_core.task.python import get_setup_data
@@ -18,20 +17,33 @@ def test_pytest_match():
1817
desc.type = 'python'
1918

2019
# no test requirements
20+
desc.metadata['get_python_setup_options'] = lambda env: {}
2121
assert not extension.match(context, env, get_setup_data(desc, env))
2222

23-
# empty test requirements
24-
desc.dependencies['test'] = {}
23+
# pytest not in tests_require
24+
desc.metadata['get_python_setup_options'] = lambda env: {
25+
'tests_require': ['nose'],
26+
}
2527
assert not extension.match(context, env, get_setup_data(desc, env))
2628

27-
# pytest not in test requirements
28-
desc.dependencies['test'] = {
29-
DependencyDescriptor('nose'),
29+
# pytest not in extras_require.test
30+
desc.metadata['get_python_setup_options'] = lambda env: {
31+
'extras_require': {
32+
'test': ['nose']
33+
},
3034
}
3135
assert not extension.match(context, env, get_setup_data(desc, env))
3236

33-
# pytest in test requirements
34-
desc.dependencies['test'] = {
35-
DependencyDescriptor('pytest'),
37+
# pytest in tests_require
38+
desc.metadata['get_python_setup_options'] = lambda env: {
39+
'tests_require': ['pytest'],
40+
}
41+
assert extension.match(context, env, get_setup_data(desc, env))
42+
43+
# pytest in extras_require.test
44+
desc.metadata['get_python_setup_options'] = lambda env: {
45+
'extras_require': {
46+
'test': ['pytest']
47+
},
3648
}
3749
assert extension.match(context, env, get_setup_data(desc, env))

0 commit comments

Comments
 (0)