Is there anyway to exclude tests with certain pyte...
# general
g
Is there anyway to exclude tests with certain pytest marks via pants? i.e.
pytest -m "not integration"
I know I can do it at the global level by adding this, but I'm wondering if there is more granularity with overrides, etc.
Copy code
[pytest]
args = ["-m", "not integration"]
n
Anything after
--
will get passed to Pytest, so you should be able to do
pants test :: -- -m "not integration"
g
That's good to know. The thing is we're using
pants --changed-since=origin/main
so I'd like the ability to do it on a config basis so that specific modules in our monorepo can exclude the integration tests from running in CI.
I'm assuming you want to filter whole files, not just methods in a file - but if those are split out into integration_test targets, then you can filter at a target level
g
@wide-midnight-78598 believe it or not the tests are a mess and I would want to filter out specific methods marked with
@pytest.mark.integration
🙂 It's a mixed bag, but I can restructure the tests (I think) and then exclude entire files.
w
😆
It's a mixed bag, but I can restructure the tests (I think) and then exclude entire files
Maybe there's a world of mixing target filtering and passthrough args as Jonas suggested
@pytest.mark.integration
Ah, okay, didn't see this - but wouldn't this be about passing through the pytest control?
n
All targets also support
tags
. So either you can tag all targets you want to exclude with something specifically, or do it for a whole tree using
__defaults__
. Then you can run your Pants commands with
--tag="-your_tag"
to exclude all those targets. Do note that it exclude it from
lint
,
check
etc. as well.
g
got it, so I can exclude tags by prefixing a hyphen (
-
)?
n
g
ah, sweet.
I think I'll do something like this and move all integration tests into specific targets so I can isolate.
w
https://www.pantsbuild.org/2.18/reference/subsystems/pytest You can also setup your toml with pytest args if needed
👍 1
Whatever you decide in the end, an alias will be your friend: https://www.pantsbuild.org/2.18/reference/subsystems/cli#alias Edit: Unintentional rhyme
🎵 1
🙌 1
g
oh my wow, how did I not know about aliases. sweeeet.
Thank you both for your help.
👍 1