Skip to content

Commit

Permalink
Add support of TEST_TAGS in python tests (#17075) (#17122)
Browse files Browse the repository at this point in the history
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 #16937.

(cherry picked from commit 3bf05f5)
  • Loading branch information
jsoriano committed Mar 19, 2020
1 parent e78ec4d commit cfcd8cf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
25 changes: 25 additions & 0 deletions libbeat/tests/system/beat/tags.py
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
3 changes: 2 additions & 1 deletion metricbeat/tests/system/metricbeat.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import os
import re
import sys
import os
import yaml

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../libbeat/tests/system')))

from beat.beat import TestCase
from beat.tags import tag
from parameterized import parameterized_class

COMMON_FIELDS = ["@timestamp", "agent", "metricset.name", "metricset.host",
Expand Down

0 comments on commit cfcd8cf

Please sign in to comment.