colcon test "1 package had test failures": test_flake8, test_pep257 and test_copyright in an ament_python package, measured
$ colcon test-result --test-result-base build/apache_pkg --all --verbose
build/apache_pkg/pytest.xml: 3 tests, 0 errors, 2 failures, 0 skipped
- apache_pkg.test.test_copyright test_copyright
<<< failure message
AssertionError: Found errors
assert 1 == 0
>>>
- apache_pkg.test.test_flake8 test_flake8
<<< failure message
AssertionError: Found 6 code style errors / warnings:
./apache_pkg/talker.py:1:1: F401 'os' imported but unused
./apache_pkg/talker.py:2:1: I201 Missing newline between import groups. 'import rclpy' is identified as Third Party and 'import os' is identified as Stdlib.
./apache_pkg/talker.py:5:1: E302 expected 2 blank lines, found 1
./apache_pkg/talker.py:7:17: Q000 Double quotes found but single quotes preferred
./apache_pkg/talker.py:8:28: Q000 Double quotes found but single quotes preferred
./apache_pkg/talker.py:8:100: E501 line too long (107 > 99 characters)
assert 1 == 0
>>>
Short answer: a package fresh from ros2 pkg create --build-type ament_python passed colcon test on Humble, Jazzy and Lyrical, with or without --license. The failures start when you add your own Python file. Three linters run as pytest tests. test_flake8 fails on style (quotes, blank lines, line length, unused imports). test_copyright fails once you remove its skip decorator and a file has no license header. test_pep257 fails on badly formatted docstrings, but not on missing ones. The fix that made every test pass was to put a license header at the top of each .py file and fix the style errors flake8 lists. Read the errors with colcon test-result --all --verbose, because colcon test itself returned 0 even when tests failed.
# Copyright 2026 Example
#
# Licensed under the Apache License, Version 2.0 (the "License");
# ... (the rest of the Apache-2.0 header, as in test/test_flake8.py)
"""Minimal talker node."""
import rclpy
from rclpy.node import Node
def main():
"""Log one message and exit."""
rclpy.init()
node = Node('talker')
node.get_logger().info(
'hello from talker, this line is longer than ninety-nine characters on purpose')
rclpy.shutdown()
If test_flake8 fails with ValueError: 'string' is not callable or FailedToLoadPlugin rather than a list of style errors, the problem is a flake8 installed with pip. That case is covered further down.

Find your error
| What you see | Cause in my runs |
|---|---|
test_copyright: AssertionError: Found errors, and in the pytest log talker.py: could not find copyright notice |
A .py file without a copyright and license header, after the generated skip decorator was removed |
test_flake8: Found N code style errors / warnings followed by Q000, E302, E501, F401, I201 |
Style errors in your files. The list is the full report |
test_pep257: Found code style errors / warnings with no detail in test-result |
Docstring format: D400, D415, D300, D200. The codes are only in the pytest log |
ValueError: 'string' is not callable |
Humble: flake8 7.4.1 from pip together with the apt python3-flake8-import-order plugin |
FailedToLoadPlugin ... module 'pycodestyle' has no attribute 'missing_whitespace_after_import_keyword' |
Humble: pip flake8 uninstalled, but pip's newer pycodestyle left behind |
ModuleNotFoundError: No module named 'flake8', colcon test exit code 2 |
Jazzy: pip install --break-system-packages removed apt's flake8, then pip uninstall removed pip's |
Warning: SelectableGroups dict interface is deprecated. Use select. |
Humble only, printed on every run. A warning, not a failure |
What I ran
On 2026-10-31 I used the official ros:humble-ros-base, ros:jazzy-ros-base and ros:lyrical-ros-base Docker images. In each one I created three packages: nolic_pkg with no --license, apache_pkg with --license Apache-2.0, and gen_pkg with --license Apache-2.0 --node-name my_node. I installed test dependencies with rosdep install --from-paths src --ignore-src -y. Then I ran colcon build, colcon test --packages-select and colcon test-result --all --verbose after each change and recorded both exit codes. The changes were a node file with style problems, removing the copyright skip, each fix option, a pip-installed flake8, and the flake8 plugins from the ROS 2 source-build setup.
What ros2 pkg create gave me:
- Without
--license,package.xmlgot<license>TODO: License declaration</license>, noLICENSEfile was written, and the tool warnedUnknown license 'TODO: License declaration'. This has been set in the package.xml, but no LICENSE file has been created.With--license Apache-2.0aLICENSEfile was created. - The
test/folder was identical either way.diff -rfound no difference on any distro. Humble and Jazzy generatetest_copyright.py,test_flake8.pyandtest_pep257.py. Lyrical addstest_mypy.pyandtest_xmllint.py. test_copyright.pycomes with@pytest.mark.skip(reason='No copyright header has been placed in the generated source file.')and a comment: "Remove the `skip` decorator once the source file(s) have a copyright header".
All three fresh packages passed on all three distros: 2 passed, 1 skipped on Humble and Jazzy, 4 passed, 1 skipped on Lyrical. The skipped test is test_copyright. So --license by itself doesn't decide whether tests pass. In my runs the license header in each file decided whether test_copyright passed, and only once the skip was gone.
test_copyright: could not find copyright notice
After I deleted the skip line, fresh nolic_pkg and apache_pkg still passed. They contain only an empty __init__.py and setup.py. gen_pkg failed right away, because the file --node-name generates has no header:
gen_pkg/my_node.py: could not find copyright notice
1 errors, checked 5 files
After I added a node file without a header, test_copyright failed the same way in both nolic_pkg and apache_pkg. Once I added the Apache header to the file, it passed in both. The TODO license in nolic_pkg's package.xml and its missing LICENSE file changed nothing in my runs.
The useful line is easy to miss. colcon test-result --verbose only shows AssertionError: Found errors. The file name appears in the captured stderr in log/latest_test/<pkg>/stdout_stderr.log, or when you run ament_copyright in the package folder:
$ ament_copyright apache_pkg
apache_pkg/talker.py: could not find copyright notice
1 errors, checked 2 files
One question asks what header a proprietary license needs. I only tested the Apache-2.0 header text copied from the generated test files.
test_flake8: which rules fired
The node file I added had an unused import os, one blank line before def main(), double quotes, and a 107-character line. On Jazzy and Lyrical, after rosdep install, test_flake8 reported six errors: F401, I201, E302, two Q000 and E501 (the block at the top of this page). On Humble the same file gave three: F401, E302 and E501. On Humble rosdep didn't install the quote and import-order plugins. After I installed the eight python3-flake8-* packages listed in the Humble source-build setup, Humble reported the same six as Jazzy.
Things that didn't fire:
- Missing docstrings. The file had no module or function docstring. No
D100orD103appeared from flake8 or pep257 on any distro, even withpython3-flake8-docstringsinstalled. - The line limit is 99, not 79. The message said
E501 line too long (107 > 99 characters).
The full report is in test-result --verbose, so this is the easiest of the three to read. Running ament_flake8 in the package folder printed the same codes.
test_pep257: docstring format, not missing docstrings
ament_pep257 printed No problems found for my node file with no docstrings at all. It fails on docstrings that exist but are formatted wrong. With a module docstring """my node module""", a function docstring in ''' quotes and a one-line docstring spread over three lines, I got this on all three distros:
gen_pkg/my_node.py:15 at module level: D400: First line should end with a period (not 'e')
gen_pkg/my_node.py:15 at module level: D415: First line should end with a period, question mark, or exclamation point (not 'e')
gen_pkg/my_node.py:19 in public function `main`: D300: Use """triple double quotes""" (found '''-quotes)
gen_pkg/my_node.py:24 in public function `helper`: D200: One-line docstring should fit on one line with quotes (found 3)
4 errors
In colcon test-result --verbose this showed only as AssertionError: Found code style errors / warnings. The codes were in the pytest log. The same file also failed test_flake8 on Jazzy (D400, D300, D200, Q002) and Lyrical (Q002 only), and passed it on Humble.
A pip-installed flake8
ament_lint#545 reports that the latest flake8 breaks ament_flake8 on Humble with ValueError: 'string' is not callable. I ran pip install -U flake8 as root inside each container and got flake8 7.4.1 on Humble and 7.5.0 on Jazzy and Lyrical.
Humble. With only the rosdep packages, flake8 7.4.1 passed. After I added the apt flake8 plugins, it failed exactly as in the issue:
/usr/lib/python3/dist-packages/flake8_import_order/flake8_linter.py:98: in register_opt
parser.add_option(*args, **kwargs)
/usr/local/lib/python3.10/dist-packages/flake8/options/manager.py:281: in add_option
self._current_group.add_argument(*option_args, **option_kwargs)
/usr/lib/python3.10/argparse.py:1447: in add_argument
raise ValueError('%r is not callable' % (type_func,))
E ValueError: 'string' is not callable
The traceback runs through the apt flake8_import_order plugin (0.18.1) and the pip flake8. On Humble, pip couldn't remove apt's flake8 4.0.1 (Not uninstalling flake8 at /usr/lib/python3/dist-packages, outside environment /usr), so it installed flake8, pycodestyle 2.15.0, pyflakes 4.0.3 and mccabe 0.7.0 into /usr/local. pip uninstall flake8 alone made things worse. apt's flake8 4.0.1 came back but loaded pip's pycodestyle:
E flake8.exceptions.FailedToLoadPlugin: Flake8 failed to load plugin "pycodestyle.missing_whitespace_after_import_keyword" due to module 'pycodestyle' has no attribute 'missing_whitespace_after_import_keyword'.
The test passed again after pip uninstall -y flake8 pycodestyle pyflakes mccabe.
Jazzy. Plain pip install was refused with the PEP 668 message. With --break-system-packages, pip uninstalled apt's flake8 7.0.0 and pycodestyle 2.11.1 and installed 7.5.0. Tests still passed, with and without the plugins. The damage came at recovery. After pip uninstall, no flake8 was left at all:
E ModuleNotFoundError: No module named 'flake8'
...
Failed <<< apache_pkg [0.79s, exited with code 2]
colcon test-result then reported 1 test, 1 error with collection failure. apt-get install --reinstall python3-flake8 python3-pycodestyle python3-pyflakes brought back 7.0.0, 2.11.1 and 3.2.0, and all tests passed.
Lyrical. Even with --break-system-packages pip stopped with Cannot uninstall pyflakes 3.4.0 and The package was installed by debian. With --ignore-installed as well, it installed 7.5.0 into /usr/local. Tests passed with and without plugins. pip uninstall returned to apt's 7.3.0 without errors.
In the issue thread a maintainer wrote "the general expectation is that the version available from the Ubuntu system packages is used". My runs fit that. The reliable state was apt's flake8, pycodestyle and pyflakes with nothing from pip in /usr/local. Check with python3 -c 'import flake8, pycodestyle; print(flake8.__file__, pycodestyle.__file__)'. Any /usr/local path means pip is in play.
The older AttributeError question on Eloquent was the same kind of mismatch with flake8 3.8, which I didn't test.
pip upgrades in the build environment also change what colcon build prints for ament_python packages: SetuptoolsDeprecationWarning: setup.py install is deprecated.
Fix options compared
Each row was run on apache_pkg with the bad node file and the copyright skip removed. Before the fix, two tests failed (test_copyright and test_flake8). Results were the same on all three distros, except for the extra Lyrical tests noted in the table.
| Option | Result | test-result exit |
|---|---|---|
| Add the license header only | test_copyright passed, test_flake8 still failed |
1 |
| Header and flake8 errors fixed | all passed (3 on Humble and Jazzy, 5 on Lyrical) | 0 |
--license Apache-2.0 at create time |
no difference from no --license; same test files, same results |
same as without |
[flake8] with max-line-length = 200 and extend-ignore = E501,F401,E302 in setup.cfg |
ignored; the same flake8 errors | 1 |
main_with_errors(argv=['--linelength', '200']) in test_flake8.py |
E501 gone, the other errors stayed |
1 |
@pytest.mark.skip on all three tests |
3 skipped (Lyrical: 2 passed, 3 skipped) |
0 |
colcon test --pytest-args -k "not flake8 and not pep257 and not copyright" |
3 deselected, and test-result counted 0 tests (Lyrical: mypy and xmllint still ran) |
0 |
colcon test --ctest-args -E flake8 |
no effect on an ament_python package, the same two failures |
1 |
The setup.cfg row answers a common question. ament_flake8 didn't read a [flake8] section there in my runs. The --linelength argument in the test file did change the line limit. Skipping or deselecting makes the run green without checking anything, so the gap shows up later in CI. Fixing the file is the only option that leaves the checks on.
Exit codes and where the results live
colcon test returned 0 on every run where tests only failed. The summary said 1 package had test failures: apache_pkg, and the package line ended with [ with test failures ]. With --return-code-on-test-failure it returned 1 for the same failures. It returned 2 only when pytest couldn't collect a test file (the missing flake8 module on Jazzy). colcon test-result returned 1 whenever there was a failure or an error and 0 otherwise. In CI, use one of those two signals, not a plain colcon test.
For an ament_python package, the JUnit file was build/<pkg>/pytest.xml, and that is what colcon test-result reads. I found no test_results folder for these packages. That folder belongs to ament_cmake packages, which I didn't test here. The full pytest output, including the copyright and pep257 details, was in log/latest_test/<pkg>/stdout_stderr.log, next to stdout.log, stderr.log, command.log and streams.log. For quick checks, I ran the linters in the package folder: ament_flake8, ament_pep257 and ament_copyright. Each returned 1 on errors and printed the file names. If colcon build for an ament_python package also shows git warnings, see listing git files failed in ament_python packages.
Version notes
- Humble (Ubuntu 22.04, Python 3.10): apt flake8 4.0.1, pycodestyle 2.8.0, pydocstyle 6.1.1, ament_lint 0.12.15.
rosdepinstalled no quote or import-order plugins, soQ000andI201only appeared after a manual install. Every run printedSelectableGroups dict interface is deprecated, which is the warning in this tutorial question. It didn't fail any test. The license warning has the typoidentitifers. - Jazzy (24.04, Python 3.12): flake8 7.0.0, pycodestyle 2.11.1, ament_lint 0.17.5, with
python3-flake8-quotesandpython3-flake8-import-orderinstalled byrosdep. - Lyrical (26.04, Python 3.14): flake8 7.3.0, pycodestyle 2.14.0, ament_lint 0.20.6, five generated tests including
test_mypyandtest_xmllint. pytest took 6 to 9 seconds per package there, against under half a second on Humble and Jazzy.
Not tested
ament_cmake packages and their ament_lint_auto tests, licenses other than Apache-2.0 (including proprietary headers), CONTRIBUTING.md checks, a --config file for ament_flake8, flake8 installed in a venv or with pip --user, ros-dev-tools on Jazzy and Lyrical, Iron, Rolling and Foxy.
FAQ
Why does colcon test say 1 package had test failures but exit with 0?
That was the default in every run. colcon test returned 0 when tests failed. Add --return-code-on-test-failure to get 1, or run colcon test-result --all --verbose, which returned 1 and printed each failure.
Does ros2 pkg create --license fix test_copyright?
No. With or without --license Apache-2.0 the generated tests were identical and test_copyright was skipped. Once the skip was removed, it failed for any .py file without a header and passed after adding one, in both packages.
Why does setup.cfg [flake8] max-line-length not work for test_flake8?
In my runs ament_flake8 ignored the [flake8] section in setup.cfg. Changing the call in test/test_flake8.py to main_with_errors(argv=['--linelength', '200']) did remove the E501 errors.
How do I fix ValueError: 'string' is not callable in test_flake8?
It came from a pip flake8 (7.4.1) with the apt flake8-import-order plugin on Humble. pip uninstall -y flake8 pycodestyle pyflakes mccabe fixed it. Removing only flake8 led to FailedToLoadPlugin. If apt's flake8 is gone too, reinstall python3-flake8 python3-pycodestyle python3-pyflakes with apt.
Why does test_pep257 pass on a file with no docstrings?
ament_pep257 reported no missing-docstring errors on any distro. It failed on badly formatted docstrings: D400 and D415 for no final period, D300 for ''' quotes, and D200 for a one-line docstring split across lines.
Measured on 2026-10-31 with ros:humble-ros-base (sha256:d9bcf2e6f72d..., rclpy 3.3.22, rclcpp 16.0.21, ros2cli 0.18.20, rmw 6.1.4, ament_lint 0.12.15, flake8 4.0.1), ros:jazzy-ros-base (sha256:8eed0a4669bb..., rclpy 7.1.12, rclcpp 28.1.22, ros2cli 0.32.13, rmw 7.3.4, ament_lint 0.17.5, flake8 7.0.0) and ros:lyrical-ros-base (sha256:3224ee150cb0..., rclpy 10.0.11, rclcpp 32.0.3, ros2cli 0.40.9, rmw 7.10.2, ament_lint 0.20.6, flake8 7.3.0), colcon-core 0.21.3. The pip flake8 was 7.4.1 on Humble and 7.5.0 on Jazzy and Lyrical. Full digests are in digests.txt.
Script and raw output: evidence folder. Questions this answers: How to configure Flake8 with colcon test, proper way to use a proprietary software license according to ament_copyright, ROS2 Humble colcon tutorial causes flake8 error, ament_flake8 fails with AttributeError, Installing latest flake8 breaks ament_flake8 on humble: ValueError: 'string' is not callable.