Exclude directories from flake8 tests when it's run through colcon?

64 Views Asked by At

Question

I tried to build a simple ROS2 package using colcon, but I struggle to exclude directories from the flake8 tests launched with colcon test-result (namely the install and build directories), even after excluding them in my setup.cfg file.

However, when I run flake8 ./ on my terminal at the root of my package, it effectively excludes them. So I guess flake8 is not reading my setup.cfg file when it's run through colcon test-result, but I'd like to stick with colcon for my testing because it's more convenient.

My ROS2 package looks like this:

├── dummy_pkg
│   ├── dummy_pkg
│   │   ├── main.py
├── build
├── test
│   ├── test_flake8.py
│   ├── test_pep257.py
│   ├── test_copyright.py    
├── install
├── logs
├── resource
├── setup.py
├── setup.cfg
└── package.xml

My setup.cgf file, like this:

[flake8]
exclude =
    .git,
    __pycache__,
    build,
    dist,
    install
    test
[develop]
script_dir=$base/lib/test_pkg
[install]
install_scripts=$base/lib/test_pkg

Any idea how to solve this?

What I've tried

I followed these steps to create the package:

  • I created an empty ROS2 package using ros2 pkg create dummy_pkg (with ament-python as build-type). I created a simple main.py that just prints something and I setup the entry point to main of main.py in package.xml. After that, I run colcon build --symlink-install in my package root, which creates the tree structure as shown above.

I can now run it using ros2 run dummy_pkg main and it outputs the correct thing.

  • I then add these lines to setup.cfg:
[flake8]
exclude =
    .git,
    __pycache__,
    build,
    dist,
    install
    test
[develop]
script_dir=$base/lib/test_pkg
[install]
install_scripts=$base/lib/test_pkg
  • After running colcon build --symlink-install again, I run colcon test-result --verbose which I expected to output only tests on my source files. However, here's what it outputs:
build/dummy_pkg/pytest.xml: 3 tests, 0 errors, 1 failure, 1 skipped
- dummy_pkg.test.test_flake8 test_flake8
  <<< failure message
    AssertionError: Found 6 code style errors / warnings:
      ./install/_local_setup_util_sh.py:14:100: E501 line too long (109 > 99 characters)
      ./install/_local_setup_util_sh.py:15:100: E501 line too long (124 > 99 characters)
      ./install/_local_setup_util_sh.py:16:100: E501 line too long (125 > 99 characters)
      ./build/dummy_pkg/build/lib/dummy_pkg/run.py:2:24: W292 no newline at end of file
      ./build/dummy_pkg/prefix_override/sitecustomize.py:3:100: E501 line too long (104 > 99 characters)
    assert 1 == 0
  >>>

Summary: 3 tests, 0 errors, 1 failure, 1 skipped

It still performs a flake8 test on the install and build directories..

0

There are 0 best solutions below