pants: `overrides` field does not work properly with tag exclusion

Describe the bug

Assume src/python/foo containing test_a.py and test_b.py, with this target in src/python/foo/BUILD:

python_tests(
    name="tests",
    overrides={
        "test_a.py": {"tags": ["xyz"]},
    }
)

./pants test src/python/foo/:: runs both tests, of course, as expected.

./pants --tag=xyz src/python/foo/:: runs just test_a.py, as expected.

However

./pants --tag=-xyz src/python/foo/:: runs both tests, whereas the user would expect it to run only test_b.py.

The reason is that --tag=-xyz src/python/foo/:: expands to [src/python/foo:tests, src/python/foo/test_b.py:tests] - the generator target does not have the tag so it is not excluded.

Then, the test goal expands to all dependencies, and since the generator src/python/foo:tests depends on src/python/foo/test_a.py:tests, that target gets pulled back into the working set.

Pants version 2.12.0.dev0 at least

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (12 by maintainers)

Commits related to this issue

Most upvoted comments

I want to work on this! Can it be assigned to me?

I’m seeing related(?) behavior using pants 2.10.0. We have the equivalent of:

python_tests(
    name="tests",
    tags=["ci"],
    overrides={
        "test_a.py": {"tags": ["skip_ci"]},
    }
)

(We tag both “ci” and “skip_ci” because we’re incrementally migrating onto pants, and explicitly marking both known-to-work and known-to-not-work tests so we know anything without a label is still TODO).

I tried all of these filter combinations in an attempt to test everything except test_a.py, but nothing worked:

./pants --tag=ci test ::
./pants --tag=-skip_ci test ::
./pants --tag=ci,-skip_ci test ::

All 3 --tag values do what I’d expect when I use ./pants filter

Stu what if tags became a moved field?

That wouldn’t address the issue in this case: this is in the presence of overrides, so the tag does not exist on the alias.