forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support of TEST_TAGS in python tests (elastic#17075)
Add a `tag(tag)` decorator that skips a test if the tag is not included in the comma-separated list of `TEST_TAGS` environment variable. This offers an initial support for the similar implementation added for mage in elastic#16937. (cherry picked from commit 3bf05f5)
- Loading branch information
Showing
2 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import os | ||
import unittest | ||
|
||
|
||
def tag(tag): | ||
""" | ||
Decorates a test function with a tag following go build tags semantics, | ||
if the tag is not included in TEST_TAGS environment variable, the test is | ||
skipped. | ||
TEST_TAGS can be a comma-separated list of tags, e.g: TEST_TAGS=oracle,mssql. | ||
""" | ||
def decorator(func): | ||
def wrapper(*args, **kwargs): | ||
set_tags = [ | ||
tag.strip() for tag in os.environ.get("TEST_TAGS", "").split(",") | ||
if tag.strip() != "" | ||
] | ||
if not tag in set_tags: | ||
raise unittest.SkipTest("tag '{}' is not included in TEST_TAGS".format(tag)) | ||
return func(*args, **kwargs) | ||
wrapper.__name__ = func.__name__ | ||
wrapper.__doc__ = func.__doc__ | ||
return wrapper | ||
|
||
return decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters