Skip to content

Commit

Permalink
ci: moved unittest config to Gitlab (#10513)
Browse files Browse the repository at this point in the history
- Removed unittest from config.templ.yaml file in circleCI
- Added unittest to the contrib.yml file in Gitlab

## Checklist
- [X] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing
strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the [library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

## Reviewer Checklist
- [x] Reviewer has checked that all the criteria below are met 
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)

---------

Co-authored-by: Jessica Gamio <jessica.gamio@nlb-int-svc-proxy-06a01ef5ff9ffd47.elb.us-gov-west-1.amazonaws.com>
  • Loading branch information
jessicagamio and Jessica Gamio authored Sep 6, 2024
1 parent a3e471b commit f2b8d8d
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 78 deletions.
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 @@ -185,6 +185,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

0 comments on commit f2b8d8d

Please sign in to comment.