Skip to content
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

Cherry-pick #17075 to 7.x: Add support of TEST_TAGS in python tests #17122

Merged
merged 1 commit into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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