Skip to content

Commit 1b09528

Browse files
feat(ci_visibility): make pytest v2 plugin the default version (#12066)
Previously, the pytest v2 plugin was disabled by default, and could be enabled by setting the `DD_PYTEST_USE_NEW_PLUGIN_BETA` variable to true. In ddtrace 3.0, the pytest v2 plugin will be *enabled* by default, and `DD_PYTEST_USE_NEW_PLUGIN_BETA` will not be used anymore. For now I'm not removing the code for the old plugin version. Instead, I'm adding an internal environment variable `_DD_PYTEST_USE_LEGACY_PLUGIN` that allows running pytest with the old plugin, and using that in the tests that depend on it. We can remove the code (and the variable) after the 3.x release, since this is not part of the public interface. ## 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)
1 parent 4d20460 commit 1b09528

12 files changed

+52
-59
lines changed

.gitlab/tests.yml

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ stages:
66
variables:
77
RIOT_RUN_CMD: riot -P -v run --exitfirst --pass-env -s
88
REPO_LANG: python # "python" is used everywhere rather than "py"
9-
DD_PYTEST_USE_NEW_PLUGIN_BETA: "true"
109
PYTEST_ADDOPTS: "-s"
1110
# CI_DEBUG_SERVICES: "true"
1211

ddtrace/contrib/internal/pytest/_plugin_v1.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,8 @@ def pytest_load_initial_conftests(early_config, parser, args):
452452

453453
def pytest_configure(config):
454454
deprecate(
455-
"this version of the pytest ddtrace plugin is slated for deprecation",
456-
message="set DD_PYTEST_USE_NEW_PLUGIN_BETA=true in your environment to preview the next version of the plugin.",
457-
removal_version="3.0.0",
455+
"this version of the pytest ddtrace plugin is deprecated",
456+
message="remove _DD_PYTEST_USE_LEGACY_PLUGIN from your environment to use the currently supported version.",
458457
category=DDTraceDeprecationWarning,
459458
)
460459
unpatch_unittest()

ddtrace/contrib/internal/pytest/_plugin_v2.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from pathlib import Path
23
import re
34
import typing as t
@@ -182,7 +183,6 @@ def pytest_load_initial_conftests(early_config, parser, args):
182183

183184
try:
184185
take_over_logger_stream_handler()
185-
log.warning("This version of the ddtrace pytest plugin is currently in beta.")
186186
# Freezegun is proactively patched to avoid it interfering with internal timing
187187
patch(freezegun=True)
188188
dd_config.test_visibility.itr_skipping_level = ITR_SKIPPING_LEVEL.SUITE
@@ -199,14 +199,14 @@ def pytest_load_initial_conftests(early_config, parser, args):
199199

200200

201201
def pytest_configure(config: pytest_Config) -> None:
202-
# The only way we end up in pytest_configure is if the environment variable is being used, and logging the warning
203-
# now ensures it shows up in output regardless of the use of the -s flag
204-
deprecate(
205-
"the DD_PYTEST_USE_NEW_PLUGIN_BETA environment variable is deprecated",
206-
message="this preview version of the pytest ddtrace plugin will become the only version.",
207-
removal_version="3.0.0",
208-
category=DDTraceDeprecationWarning,
209-
)
202+
if os.getenv("DD_PYTEST_USE_NEW_PLUGIN_BETA"):
203+
# Logging the warning at this point ensures it shows up in output regardless of the use of the -s flag.
204+
deprecate(
205+
"the DD_PYTEST_USE_NEW_PLUGIN_BETA environment variable is deprecated",
206+
message="the new pytest plugin is now the default version. No additional configurations are required.",
207+
removal_version="3.0.0",
208+
category=DDTraceDeprecationWarning,
209+
)
210210

211211
try:
212212
if is_enabled(config):

ddtrace/contrib/internal/pytest/_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
_NODEID_REGEX = re.compile("^(((?P<module>.*)/)?(?P<suite>[^/]*?))::(?P<name>.*?)$")
3232

33-
_USE_PLUGIN_V2 = asbool(os.environ.get("DD_PYTEST_USE_NEW_PLUGIN_BETA", "false"))
33+
_USE_PLUGIN_V2 = not asbool(os.environ.get("_DD_PYTEST_USE_LEGACY_PLUGIN", "false"))
3434

3535

3636
class _PYTEST_STATUS:

docs/configuration.rst

-16
Original file line numberDiff line numberDiff line change
@@ -616,22 +616,6 @@ Test Visibility
616616
version_added:
617617
v2.16.0:
618618

619-
DD_PYTEST_USE_NEW_PLUGIN_BETA:
620-
type: Boolean
621-
default: False
622-
623-
description: |
624-
Configures the ``CIVisibility`` service to use a beta release of the new version of the pytest plugin,
625-
supporting `Auto Test Retries <https://docs.datadoghq.com/tests/flaky_test_management/auto_test_retries>`_,
626-
`Early Flake Detection <https://docs.datadoghq.com/tests/flaky_test_management/early_flake_detection>`_, and
627-
improved coverage collection for `Test Impact Analysis
628-
<https://docs.datadoghq.com/tests/test_impact_analysis>`_. This version of the plugin will become the default in
629-
the future. See the `release notes for v2.18.0 <https://github.com/DataDog/dd-trace-py/releases/tag/v2.18.0>`_
630-
for more information.
631-
632-
version_added:
633-
v2.18.0:
634-
635619
DD_CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS:
636620
type: Integer
637621
default: 500

hatch.toml

+2-6
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,6 @@ dependencies = [
558558
]
559559

560560
[envs.pytest_plugin_v2.env-vars]
561-
DD_PYTEST_USE_NEW_PLUGIN_BETA = "true"
562561
DD_AGENT_PORT = "9126"
563562

564563
[envs.pytest_plugin_v2.scripts]
@@ -599,9 +598,6 @@ dependencies = [
599598
"hypothesis",
600599
]
601600

602-
[envs.freezegun.env-vars]
603-
DD_PYTEST_USE_NEW_PLUGIN_BETA = "true"
604-
605601
[envs.freezegun.scripts]
606602
test = [
607603
"pytest tests/contrib/freezegun {args:}",
@@ -637,6 +633,6 @@ tested_pytest_plugin_version = ["v1", "v2"]
637633

638634
[envs.selenium.overrides]
639635
matrix.tested_pytest_plugin_version.env-vars = [
640-
{ key = "_TESTED_PYTEST_PLUGIN_VERSION", value = "false", if = ["v1"]},
641-
{ key = "_TESTED_PYTEST_PLUGIN_VERSION", value = "true", if = ["v2"]}
636+
{ key = "_TESTED_PYTEST_LEGACY_PLUGIN", value = "true", if = ["v1"]},
637+
{ key = "_TESTED_PYTEST_LEGACY_PLUGIN", value = "false", if = ["v2"]}
642638
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
upgrade:
3+
- |
4+
CI Visibility: Official release of the new version of the pytest plugin, introducing the following features:
5+
- `Auto Test Retries <https://docs.datadoghq.com/tests/flaky_test_management/auto_test_retries>`_
6+
- `Early Flake Detection <https://docs.datadoghq.com/tests/flaky_test_management/early_flake_detection>`_
7+
- Improved coverage collection for `Test Impact Analysis <https://docs.datadoghq.com/tests/test_impact_analysis>`_
8+
(formerly Intelligent Test Runner), using an internal collection method instead of `coverage.py
9+
<https://github.com/nedbat/coveragepy>`_, with improved dependency discovery.
10+
11+
**NOTE:** this new version of the plugin introduces breaking changes:
12+
- ``module``, ``suite``, and ``test`` names are now parsed from the ``item.nodeid`` attribute
13+
- test names now include the class for class-based tests
14+
- Test skipping by Test Impact Analysis (formerly Intelligent Test Runner) is now done at the suite level, instead
15+
of at the test level
16+
17+
A beta version of the plugin had been available since v2.18.0, and could be enabled via the
18+
``DD_PYTEST_USE_NEW_PLUGIN_BETA`` environment variable. The new version is now the default, and the environment
19+
variable is not used anymore.

riotfile.py

+10-14
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
103103
"DD_INJECT_FORCE": "1",
104104
"DD_PATCH_MODULES": "unittest:false",
105105
"CMAKE_BUILD_PARALLEL_LEVEL": "12",
106-
"DD_PYTEST_USE_NEW_PLUGIN_BETA": "true",
107106
},
108107
venvs=[
109108
Venv(
@@ -1604,7 +1603,6 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
16041603
},
16051604
env={
16061605
"DD_AGENT_PORT": "9126",
1607-
"DD_PYTEST_USE_NEW_PLUGIN_BETA": "1",
16081606
},
16091607
venvs=[
16101608
Venv(
@@ -1634,12 +1632,12 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
16341632
venvs=[
16351633
Venv(
16361634
env={
1637-
"DD_PYTEST_USE_NEW_PLUGIN_BETA": "0",
1635+
"_DD_PYTEST_USE_LEGACY_PLUGIN": "true",
16381636
},
16391637
),
16401638
Venv(
16411639
env={
1642-
"DD_PYTEST_USE_NEW_PLUGIN_BETA": "1",
1640+
"_DD_PYTEST_USE_LEGACY_PLUGIN": "false",
16431641
},
16441642
),
16451643
],
@@ -1662,12 +1660,12 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
16621660
venvs=[
16631661
Venv(
16641662
env={
1665-
"DD_PYTEST_USE_NEW_PLUGIN_BETA": "0",
1663+
"DD_PYTEST_LEGACY_PLUGIN": "true",
16661664
},
16671665
),
16681666
Venv(
16691667
env={
1670-
"DD_PYTEST_USE_NEW_PLUGIN_BETA": "1",
1668+
"_DD_PYTEST_USE_LEGACY_PLUGIN": "false",
16711669
},
16721670
),
16731671
],
@@ -1734,12 +1732,12 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
17341732
venvs=[
17351733
Venv(
17361734
env={
1737-
"DD_PYTEST_USE_NEW_PLUGIN_BETA": "0",
1735+
"_DD_PYTEST_USE_LEGACY_PLUGIN": "true",
17381736
},
17391737
),
17401738
Venv(
17411739
env={
1742-
"DD_PYTEST_USE_NEW_PLUGIN_BETA": "1",
1740+
"_DD_PYTEST_USE_LEGACY_PLUGIN": "false",
17431741
},
17441742
),
17451743
],
@@ -1755,12 +1753,12 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
17551753
venvs=[
17561754
Venv(
17571755
env={
1758-
"DD_PYTEST_USE_NEW_PLUGIN_BETA": "0",
1756+
"_DD_PYTEST_USE_LEGACY_PLUGIN": "true",
17591757
},
17601758
),
17611759
Venv(
17621760
env={
1763-
"DD_PYTEST_USE_NEW_PLUGIN_BETA": "1",
1761+
"_DD_PYTEST_USE_LEGACY_PLUGIN": "false",
17641762
},
17651763
),
17661764
],
@@ -1783,7 +1781,7 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
17831781
]
17841782
},
17851783
env={
1786-
"DD_PYTEST_USE_NEW_PLUGIN_BETA": "0",
1784+
"_DD_PYTEST_USE_LEGACY_PLUGIN": "true",
17871785
},
17881786
),
17891787
Venv(
@@ -1793,7 +1791,7 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
17931791
]
17941792
},
17951793
env={
1796-
"DD_PYTEST_USE_NEW_PLUGIN_BETA": "1",
1794+
"_DD_PYTEST_USE_LEGACY_PLUGIN": "false",
17971795
},
17981796
),
17991797
],
@@ -3072,8 +3070,6 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
30723070
env={
30733071
"DD_PROFILING_ENABLE_ASSERTS": "1",
30743072
"DD_PROFILING_EXPORT_LIBDD_ENABLED": "1",
3075-
# Enable pytest v2 plugin to handle pytest-cpp items in the test suite
3076-
"DD_PYTEST_USE_NEW_PLUGIN_BETA": "1",
30773073
"CPUCOUNT": "12",
30783074
},
30793075
pkgs={

tests/contrib/flask/test_appsec_flask_pytest_iast_no_snapshot.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
@pytest.mark.parametrize("iast_enabled", ["true", "false"])
1111
@pytest.mark.parametrize("iast_request_sampling", ["100.0", "0.0"])
12-
@pytest.mark.parametrize("pytest_use_new_plugin", ["true", "false"])
13-
def test_flask_pytest_iast(iast_enabled, iast_request_sampling, pytest_use_new_plugin):
12+
@pytest.mark.parametrize("pytest_use_legacy_plugin", ["false", "true"])
13+
def test_flask_pytest_iast(iast_enabled, iast_request_sampling, pytest_use_legacy_plugin):
1414
from tests.utils import _build_env
1515

1616
env = _build_env()
@@ -21,7 +21,7 @@ def test_flask_pytest_iast(iast_enabled, iast_request_sampling, pytest_use_new_p
2121
"DD_TRACE_SQLITE_ENABLED": "0",
2222
"DD_IAST_ENABLED": iast_enabled,
2323
"DD_TRACE_DEBUG": "true",
24-
"DD_PYTEST_USE_NEW_PLUGIN_BETA": pytest_use_new_plugin,
24+
"_DD_PYTEST_USE_LEGACY_PLUGIN": pytest_use_legacy_plugin,
2525
"DD_IAST_REQUEST_SAMPLING": iast_request_sampling,
2626
# "DD_API_KEY": "invalidapikey",
2727
# "DD_CIVISIBILITY_AGENTLESS_ENABLED": "1",

tests/contrib/pytest/test_pytest_snapshot.py

+3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def test_add_two_number_list():
8585
DD_PATCH_MODULES="sqlite3:false",
8686
CI_PROJECT_DIR=str(self.testdir.tmpdir),
8787
DD_CIVISIBILITY_AGENTLESS_ENABLED="false",
88+
_DD_PYTEST_USE_LEGACY_PLUGIN="true",
8889
)
8990
),
9091
)
@@ -130,6 +131,7 @@ def test_add_two_number_list():
130131
DD_PATCH_MODULES="sqlite3:false",
131132
CI_PROJECT_DIR=str(self.testdir.tmpdir),
132133
DD_CIVISIBILITY_AGENTLESS_ENABLED="false",
134+
_DD_PYTEST_USE_LEGACY_PLUGIN="true",
133135
)
134136
),
135137
)
@@ -164,6 +166,7 @@ def test_call_urllib():
164166
DD_CIVISIBILITY_ITR_ENABLED="false",
165167
CI_PROJECT_DIR=str(self.testdir.tmpdir),
166168
DD_CIVISIBILITY_AGENTLESS_ENABLED="false",
169+
_DD_PYTEST_USE_LEGACY_PLUGIN="true",
167170
DD_PATCH_MODULES="httpx:true",
168171
)
169172
),

tests/contrib/pytest/test_pytest_snapshot_v2.py

-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ def test_add_two_number_list():
8585
DD_PATCH_MODULES="sqlite3:false",
8686
CI_PROJECT_DIR=str(self.testdir.tmpdir),
8787
DD_CIVISIBILITY_AGENTLESS_ENABLED="false",
88-
DD_PYTEST_USE_NEW_PLUGIN_BETA="true",
8988
)
9089
),
9190
)
@@ -131,7 +130,6 @@ def test_add_two_number_list():
131130
DD_PATCH_MODULES="sqlite3:false",
132131
CI_PROJECT_DIR=str(self.testdir.tmpdir),
133132
DD_CIVISIBILITY_AGENTLESS_ENABLED="false",
134-
DD_PYTEST_USE_NEW_PLUGIN_BETA="true",
135133
)
136134
),
137135
)
@@ -167,7 +165,6 @@ def test_call_urllib():
167165
CI_PROJECT_DIR=str(self.testdir.tmpdir),
168166
DD_CIVISIBILITY_AGENTLESS_ENABLED="false",
169167
DD_PATCH_MODULES="httpx:true",
170-
DD_PYTEST_USE_NEW_PLUGIN_BETA="true",
171168
)
172169
),
173170
)

tests/contrib/selenium/test_selenium_chrome.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def test_selenium_local_pass():
116116
DD_PATCH_MODULES="sqlite3:false",
117117
CI_PROJECT_DIR=str(testdir.tmpdir),
118118
DD_CIVISIBILITY_AGENTLESS_ENABLED="false",
119-
DD_PYTEST_USE_NEW_PLUGIN_BETA=os.environ.get("_TESTED_PYTEST_PLUGIN_VERSION"),
119+
_DD_PYTEST_USE_LEGACY_PLUGIN=os.environ.get("_TESTED_PYTEST_LEGACY_PLUGIN"),
120120
)
121121
),
122122
)
@@ -167,7 +167,7 @@ def test_selenium_local_pass():
167167
DD_PATCH_MODULES="sqlite3:false",
168168
CI_PROJECT_DIR=str(testdir.tmpdir),
169169
DD_CIVISIBILITY_AGENTLESS_ENABLED="false",
170-
DD_PYTEST_USE_NEW_PLUGIN_BETA=os.environ.get("_TESTED_PYTEST_PLUGIN_VERSION"),
170+
_DD_PYTEST_USE_LEGACY_PLUGIN=os.environ.get("_TESTED_PYTEST_LEGACY_PLUGIN"),
171171
)
172172
),
173173
)
@@ -221,7 +221,7 @@ def test_selenium_local_unpatch():
221221
DD_PATCH_MODULES="sqlite3:false",
222222
CI_PROJECT_DIR=str(testdir.tmpdir),
223223
DD_CIVISIBILITY_AGENTLESS_ENABLED="false",
224-
DD_PYTEST_USE_NEW_PLUGIN_BETA=os.environ.get("_TESTED_PYTEST_PLUGIN_VERSION"),
224+
_DD_PYTEST_USE_LEGACY_PLUGIN=os.environ.get("_TESTED_PYTEST_LEGACY_PLUGIN"),
225225
)
226226
),
227227
)

0 commit comments

Comments
 (0)