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

ci: moved unittest config to Gitlab #10513

Merged
merged 7 commits into from
Sep 6, 2024
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
7 changes: 0 additions & 7 deletions .circleci/config.templ.yml
Original file line number Diff line number Diff line change
Expand Up @@ -830,13 +830,6 @@ jobs:
env: 'pytest_plugin_v2'
snapshot: true

unittest:
<<: *machine_executor
steps:
- run_test:
pattern: 'unittest'
snapshot: true

asynctest:
executor: ddtrace_dev
steps:
Expand Down
5 changes: 5 additions & 0 deletions .gitlab/tests/contrib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ tornado:
variables:
SUITE_NAME: "tornado"

unittest:
extends: .test_base_riot_snapshot
variables:
SUITE_NAME: "unittest"

wsgi:
extends: .test_base_riot_snapshot
variables:
Expand Down
3 changes: 3 additions & 0 deletions riotfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1646,6 +1646,9 @@ def select_pys(min_version=MIN_PYTHON_VERSION, max_version=MAX_PYTHON_VERSION):
env={
"DD_PATCH_MODULES": "unittest:true",
"DD_AGENT_PORT": "9126",
# gitlab sets the service name to the repo name while locally the default service name is used
# setting DD_SERVICE ensures the output of the snapshot tests is consistent.
"DD_UNITTEST_SERVICE": "dd-trace-py",
},
pys=select_pys(),
),
Expand Down
44 changes: 33 additions & 11 deletions tests/contrib/unittest/test_unittest_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@

SNAPSHOT_IGNORES_ITR_COVERAGE = ["metrics.test.source.start", "metrics.test.source.end", "meta.test.source.file"]

SNAPSHOT_IGNORES_GITLAB = [
"meta._dd.ci.env_vars",
"meta.ci.job.name",
"meta.ci.job.url",
"meta.ci.node.labels",
"meta.ci.node.name",
"meta.ci.pipeline.id",
"meta.ci.pipeline.name",
"meta.ci.pipeline.number",
"meta.ci.pipeline.url",
"meta.ci.provider.name",
"meta.ci.stage.name",
"meta.ci.workspace_path",
"meta.git.branch",
"meta.git.commit.author.date",
"meta.git.commit.author.email",
"meta.git.commit.author.name",
"meta.git.commit.message",
"meta.git.commit.sha",
"meta.git.repository_url",
]


class UnittestSnapshotTestCase(TracerTestCase):
@pytest.fixture(autouse=True)
Expand All @@ -38,7 +60,7 @@ def fixtures(self, testdir, monkeypatch, git_repo):
self.monkeypatch = monkeypatch
self.git_repo = git_repo

@snapshot(ignores=SNAPSHOT_IGNORES)
@snapshot(ignores=SNAPSHOT_IGNORES + SNAPSHOT_IGNORES_GITLAB)
def test_unittest_generates_source_file_data(self):
ret_false = """
def ret_false():
Expand Down Expand Up @@ -71,7 +93,7 @@ def test_third(self):
["ddtrace-run", "python", "-m", "unittest"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
)

@snapshot(ignores=SNAPSHOT_IGNORES + SNAPSHOT_IGNORES_ITR_COVERAGE)
@snapshot(ignores=SNAPSHOT_IGNORES + SNAPSHOT_IGNORES_ITR_COVERAGE + SNAPSHOT_IGNORES_GITLAB)
def test_unittest_generates_coverage_correctly(self):
ret_false = """
def ret_false():
Expand Down Expand Up @@ -108,7 +130,7 @@ def test_second(self):
["ddtrace-run", "python", "-m", "unittest"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
)

@snapshot(ignores=SNAPSHOT_IGNORES + SNAPSHOT_IGNORES_ITR_COVERAGE)
@snapshot(ignores=SNAPSHOT_IGNORES + SNAPSHOT_IGNORES_ITR_COVERAGE + SNAPSHOT_IGNORES_GITLAB)
def test_unittest_generates_coverage_correctly_with_skipped(self):
ret_false = """
def ret_false():
Expand Down Expand Up @@ -144,7 +166,7 @@ def test_second(self):
with override_env(dict(DD_API_KEY="foobar.baz", DD_CIVISIBILITY_ITR_ENABLED="1")):
subprocess.run(["ddtrace-run", "python", "-m", "unittest"])

@snapshot(ignores=SNAPSHOT_IGNORES + SNAPSHOT_IGNORES_ITR_COVERAGE)
@snapshot(ignores=SNAPSHOT_IGNORES + SNAPSHOT_IGNORES_ITR_COVERAGE + SNAPSHOT_IGNORES_GITLAB)
def test_unittest_will_report_coverage_by_test_with_itr_skipped(self):
ret_false = """
def ret_false():
Expand Down Expand Up @@ -193,7 +215,7 @@ def test_second(self):
with override_env(dict(DD_API_KEY="foobar.baz", DD_CIVISIBILITY_ITR_ENABLED="1")):
subprocess.run(["ddtrace-run", "python", "-m", "unittest"])

@snapshot(ignores=SNAPSHOT_IGNORES + SNAPSHOT_IGNORES_ITR_COVERAGE)
@snapshot(ignores=SNAPSHOT_IGNORES + SNAPSHOT_IGNORES_ITR_COVERAGE + SNAPSHOT_IGNORES_GITLAB)
def test_unittest_will_report_coverage_by_test_with_itr_skipped_multiple(self):
ret_false = """
def ret_false():
Expand Down Expand Up @@ -242,7 +264,7 @@ def test_second(self):
with override_env(dict(DD_API_KEY="foobar.baz", DD_CIVISIBILITY_ITR_ENABLED="1")):
subprocess.run(["ddtrace-run", "python", "-m", "unittest"])

@snapshot(ignores=SNAPSHOT_IGNORES + SNAPSHOT_IGNORES_ITR_COVERAGE)
@snapshot(ignores=SNAPSHOT_IGNORES + SNAPSHOT_IGNORES_ITR_COVERAGE + SNAPSHOT_IGNORES_GITLAB)
def test_unittest_will_force_run_unskippable_tests(self):
ret_false = """
def ret_false():
Expand Down Expand Up @@ -282,7 +304,7 @@ def test_second(self):
with override_env(dict(DD_API_KEY="foobar.baz", DD_CIVISIBILITY_ITR_ENABLED="1")):
subprocess.run(["ddtrace-run", "python", "-m", "unittest"])

@snapshot(ignores=SNAPSHOT_IGNORES + SNAPSHOT_IGNORES_ITR_COVERAGE)
@snapshot(ignores=SNAPSHOT_IGNORES + SNAPSHOT_IGNORES_ITR_COVERAGE + SNAPSHOT_IGNORES_GITLAB)
def test_unittest_will_force_run_multiple_unskippable_tests(self):
ret_false = """
def ret_false():
Expand Down Expand Up @@ -326,7 +348,7 @@ def test_third(self):
with override_env(dict(DD_API_KEY="foobar.baz", DD_CIVISIBILITY_ITR_ENABLED="1")):
subprocess.run(["ddtrace-run", "python", "-m", "unittest"])

@snapshot(ignores=SNAPSHOT_IGNORES + SNAPSHOT_IGNORES_ITR_COVERAGE)
@snapshot(ignores=SNAPSHOT_IGNORES + SNAPSHOT_IGNORES_ITR_COVERAGE + SNAPSHOT_IGNORES_GITLAB)
def test_unittest_will_skip_invalid_unskippable_tests(self):
ret_false = """
def ret_false():
Expand Down Expand Up @@ -375,7 +397,7 @@ def test_fourth(self):
with override_env(dict(DD_API_KEY="foobar.baz", DD_CIVISIBILITY_ITR_ENABLED="1")):
subprocess.run(["ddtrace-run", "python", "-m", "unittest"])

@snapshot(ignores=SNAPSHOT_IGNORES + SNAPSHOT_IGNORES_ITR_COVERAGE)
@snapshot(ignores=SNAPSHOT_IGNORES + SNAPSHOT_IGNORES_ITR_COVERAGE + SNAPSHOT_IGNORES_GITLAB)
def test_unittest_will_skip_unskippable_test_if_skip_decorator(self):
ret_false = """
def ret_false():
Expand Down Expand Up @@ -428,7 +450,7 @@ def test_fourth(self):
with override_env(dict(DD_API_KEY="foobar.baz", DD_CIVISIBILITY_ITR_ENABLED="1")):
subprocess.run(["ddtrace-run", "python", "-m", "unittest"])

@snapshot(ignores=SNAPSHOT_IGNORES + SNAPSHOT_IGNORES_ITR_COVERAGE)
@snapshot(ignores=SNAPSHOT_IGNORES + SNAPSHOT_IGNORES_ITR_COVERAGE + SNAPSHOT_IGNORES_GITLAB)
def test_unittest_will_include_custom_tests(self):
ret_false = """
def ret_false():
Expand Down Expand Up @@ -474,7 +496,7 @@ def test_second(self):
):
subprocess.run(["ddtrace-run", "python", "-m", "unittest"])

@snapshot(ignores=SNAPSHOT_IGNORES + SNAPSHOT_IGNORES_ITR_COVERAGE)
@snapshot(ignores=SNAPSHOT_IGNORES + SNAPSHOT_IGNORES_ITR_COVERAGE + SNAPSHOT_IGNORES_GITLAB)
def test_unittest_will_include_lines_pct(self):
tools = """
def add_two_number_list(list_1, list_2):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[[
{
"name": "unittest.test_session",
"service": "unittest",
"service": "dd-trace-py",
"resource": "python -m unittest",
"trace_id": 0,
"span_id": 1,
Expand Down Expand Up @@ -45,7 +45,7 @@
},
{
"name": "unittest.test_module",
"service": "unittest",
"service": "dd-trace-py",
"resource": "test_my_coverage",
"trace_id": 0,
"span_id": 2,
Expand Down Expand Up @@ -89,7 +89,7 @@
},
{
"name": "unittest.test_suite",
"service": "unittest",
"service": "dd-trace-py",
"resource": "CoverageTestCase",
"trace_id": 0,
"span_id": 3,
Expand Down Expand Up @@ -133,7 +133,7 @@
},
{
"name": "unittest.test",
"service": "unittest",
"service": "dd-trace-py",
"resource": "CoverageTestCase.test_cov",
"trace_id": 0,
"span_id": 4,
Expand Down Expand Up @@ -183,7 +183,7 @@
},
{
"name": "unittest.test",
"service": "unittest",
"service": "dd-trace-py",
"resource": "CoverageTestCase.test_second",
"trace_id": 0,
"span_id": 5,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[[
{
"name": "unittest.test_session",
"service": "unittest",
"service": "dd-trace-py",
"resource": "python -m unittest",
"trace_id": 0,
"span_id": 1,
Expand Down Expand Up @@ -45,7 +45,7 @@
},
{
"name": "unittest.test_module",
"service": "unittest",
"service": "dd-trace-py",
"resource": "test_my_coverage",
"trace_id": 0,
"span_id": 2,
Expand Down Expand Up @@ -89,7 +89,7 @@
},
{
"name": "unittest.test_suite",
"service": "unittest",
"service": "dd-trace-py",
"resource": "CoverageTestCase",
"trace_id": 0,
"span_id": 3,
Expand Down Expand Up @@ -133,7 +133,7 @@
},
{
"name": "unittest.test",
"service": "unittest",
"service": "dd-trace-py",
"resource": "CoverageTestCase.test_cov",
"trace_id": 0,
"span_id": 4,
Expand Down Expand Up @@ -183,7 +183,7 @@
},
{
"name": "unittest.test",
"service": "unittest",
"service": "dd-trace-py",
"resource": "CoverageTestCase.test_second",
"trace_id": 0,
"span_id": 5,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[[
{
"name": "unittest.test_session",
"service": "unittest",
"service": "dd-trace-py",
"resource": "python -m unittest",
"trace_id": 0,
"span_id": 1,
Expand Down Expand Up @@ -45,7 +45,7 @@
},
{
"name": "unittest.test_module",
"service": "unittest",
"service": "dd-trace-py",
"resource": "test_source_file",
"trace_id": 0,
"span_id": 2,
Expand Down Expand Up @@ -89,7 +89,7 @@
},
{
"name": "unittest.test_suite",
"service": "unittest",
"service": "dd-trace-py",
"resource": "CoverageTestCase",
"trace_id": 0,
"span_id": 3,
Expand Down Expand Up @@ -133,7 +133,7 @@
},
{
"name": "unittest.test",
"service": "unittest",
"service": "dd-trace-py",
"resource": "CoverageTestCase.test_first",
"trace_id": 0,
"span_id": 4,
Expand Down Expand Up @@ -182,7 +182,7 @@
},
{
"name": "unittest.test",
"service": "unittest",
"service": "dd-trace-py",
"resource": "CoverageTestCase.test_second",
"trace_id": 0,
"span_id": 5,
Expand Down Expand Up @@ -231,7 +231,7 @@
},
{
"name": "unittest.test",
"service": "unittest",
"service": "dd-trace-py",
"resource": "CoverageTestCase.test_third",
"trace_id": 0,
"span_id": 6,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[[
{
"name": "unittest.test_session",
"service": "unittest",
"service": "dd-trace-py",
"resource": "python -m unittest",
"trace_id": 0,
"span_id": 1,
Expand Down Expand Up @@ -51,7 +51,7 @@
},
{
"name": "unittest.test_module",
"service": "unittest",
"service": "dd-trace-py",
"resource": "test_my_coverage",
"trace_id": 0,
"span_id": 2,
Expand Down Expand Up @@ -101,7 +101,7 @@
},
{
"name": "unittest.test_suite",
"service": "unittest",
"service": "dd-trace-py",
"resource": "CoverageTestCase",
"trace_id": 0,
"span_id": 3,
Expand Down Expand Up @@ -145,7 +145,7 @@
},
{
"name": "unittest.test",
"service": "unittest",
"service": "dd-trace-py",
"resource": "CoverageTestCase.test_cov",
"trace_id": 0,
"span_id": 4,
Expand Down Expand Up @@ -197,7 +197,7 @@
},
{
"name": "unittest.test",
"service": "unittest",
"service": "dd-trace-py",
"resource": "CoverageTestCase.test_second",
"trace_id": 0,
"span_id": 5,
Expand Down Expand Up @@ -249,7 +249,7 @@
},
{
"name": "unittest.test",
"service": "unittest",
"service": "dd-trace-py",
"resource": "CoverageTestCase.test_third",
"trace_id": 0,
"span_id": 6,
Expand Down
Loading
Loading