Skip to content

Commit

Permalink
Add support of TEST_TAGS in python tests
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 elastic#16937.
  • Loading branch information
jsoriano committed Mar 18, 2020
1 parent ae43c2e commit 3dae8a0
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion metricbeat/tests/system/metricbeat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import re
import sys
import os
import unittest
import yaml

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../libbeat/tests/system')))
Expand Down Expand Up @@ -139,3 +140,26 @@ def parameterized_with_supported_versions(base_class):
variants = supported_versions(versions_path)
decorator = parameterized_class(['COMPOSE_ENV'], variants)
decorator(base_class)


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

0 comments on commit 3dae8a0

Please sign in to comment.