-
Notifications
You must be signed in to change notification settings - Fork 12
Add --tag-filters option to filter tests using execution_tag marker
#83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --tag-filters option to filter tests using execution_tag marker
#83
Conversation
af0becc to
07121b3
Compare
07121b3 to
bf552fa
Compare
| if plugin: | ||
| api = API(os.environ) | ||
| numprocesses = config.getoption("numprocesses") | ||
| numprocesses = config.getoption("numprocesses", None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the tests I added failed in CI because numprocesses option doesn't exists in the subprocess environment. I added None as default to prevent error being raised when evaluation that option.
--tag-filters option to filter tests using execution_tag marker--tag-filters option to filter tests using execution_tag marker
Add a new --tag-filters CLI flag that allows filtering tests by execution tags. This is useful for selectively running subsets of tests. Currently only Pytest is supported via markers [1]. When specified, the tag filter is passed to pytest via the -m flag (e.g., pytest -m "test_execution"). We will replace the default marker filter with a custom filter option implemented in the Python test collector [2] Changes: - Add --tag-filters flag and BUILDKITE_TEST_ENGINE_TAG_FILTERS env var - Add TagFilters field to Config struct - Update Pytest runner to use -m flag when tag filters are specified. (This will be replaced with a custom filter) - Add test coverage for marker-based filtering for pytest Example usage: bktec run --tag-filters "slow" BUILDKITE_TEST_ENGINE_TAG_FILTERS="not integration" bktec run [1] https://docs.pytest.org/en/7.1.x/example/markers.html [2] buildkite/test-collector-python#83
| dest="mergejson", | ||
| help='merge json output with existing file, if it exists' | ||
| ) | ||
| group.addoption( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| from pathlib import Path | ||
|
|
||
| def test_add_tag_to_execution_data(tmp_path, fake_env): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job backfilling a test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
I had thoughts about : as the separator between a tag key and value. My suggestion was = but it doesn't matter as both characters are not permitted characters in a key.
The integration test proves test examples can be filtered/collected from one file. There is no reason for me to believe this doesn't extend to multiple files with similar behaviour to the built in marker selector EDIT: I can confirm it works as expected with multiple files!
Add a new --tag-filters CLI flag that allows filtering tests by execution tags. This is useful for selectively running subsets of tests. Currently only Pytest is supported via markers [1]. When specified, the tag filter is passed to pytest via the -m flag (e.g., pytest -m "test_execution"). We will replace the default marker filter with a custom filter option implemented in the Python test collector [2] Changes: - Add --tag-filters flag and BUILDKITE_TEST_ENGINE_TAG_FILTERS env var - Add TagFilters field to Config struct - Update Pytest runner to use -m flag when tag filters are specified. (This will be replaced with a custom filter) - Add test coverage for marker-based filtering for pytest Example usage: bktec run --tag-filters "slow" BUILDKITE_TEST_ENGINE_TAG_FILTERS="not integration" bktec run [1] https://docs.pytest.org/en/7.1.x/example/markers.html [2] buildkite/test-collector-python#83
|
I've integrated this change with |
Test Engine Tags can be applied to a test using
@pytest.mark.execution_tag(“key”, “value”). However, pytest built-in-moption doesn’t support filtering tests using marker arguments. It can filter tests that have anyexecution_tagmarkers, but it can't filter tests that haveexecution_tagmarker with specifickeyandvalue.This PR adds new custom options
--tag-filtersto filter tests based onexecution_tag'skey&value.Then to filter tests with execution tag