-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: fix subprocess wrapper [backport 1.18] (#6646)
Backport 8863df6 from #6624 to 1.18. This change fixes the `pytest.mark.subprocess` decorator ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [x] 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: Federico Mon <[email protected]>
- Loading branch information
1 parent
cc8d9dc
commit a176097
Showing
6 changed files
with
120 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# | ||
# This file is autogenerated by pip-compile with Python 3.10 | ||
# by the following command: | ||
# | ||
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/1c84c16.in | ||
# | ||
attrs==23.1.0 | ||
coverage[toml]==7.2.7 | ||
exceptiongroup==1.1.2 | ||
hypothesis==6.45.0 | ||
iniconfig==2.0.0 | ||
mock==5.1.0 | ||
opentracing==2.4.0 | ||
packaging==23.1 | ||
pluggy==1.2.0 | ||
pytest==7.4.0 | ||
pytest-cov==4.1.0 | ||
pytest-mock==3.11.1 | ||
sortedcontainers==2.4.0 | ||
tomli==2.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from tests.utils import TracerTestCase | ||
from tests.utils import override_env | ||
|
||
|
||
class ConftestTestCase(TracerTestCase): | ||
""" | ||
Test case to verify conftest code works as expected | ||
""" | ||
|
||
@pytest.fixture(autouse=True) | ||
def fixtures(self, testdir): | ||
""" | ||
Fixtures to use in tests | ||
""" | ||
self.testdir = testdir | ||
|
||
def makeconftest(self, conftest_rel_path="../conftest.py"): | ||
""" | ||
Copy tests/conftest.py contents to the testdir conftest | ||
""" | ||
this_dir = os.path.dirname(__file__) | ||
abs_file_path = os.path.join(this_dir, conftest_rel_path) | ||
with open(abs_file_path, encoding="utf-8") as conftest: | ||
self.testdir.makeconftest(conftest.read()) | ||
|
||
def inline_run(self, *args): | ||
""" | ||
Override inline_run to use our conftest | ||
""" | ||
with override_env({"DD_API_KEY": "foobar.baz"}): | ||
self.makeconftest() | ||
return self.testdir.inline_run(*args) | ||
|
||
def test_subprocess_fail(self): | ||
""" | ||
Test a failing test with subprocess decorator | ||
""" | ||
py_file = self.testdir.makepyfile( | ||
""" | ||
import pytest | ||
@pytest.mark.subprocess() | ||
def test_fail(): | ||
assert False | ||
""" | ||
) | ||
file_name = os.path.basename(py_file.strpath) | ||
rec = self.inline_run(file_name) | ||
rec.assertoutcome(passed=0, failed=1, skipped=0) | ||
|
||
def test_subprocess_pass(self): | ||
""" | ||
Test a passing test with subprocess decorator | ||
""" | ||
py_file = self.testdir.makepyfile( | ||
""" | ||
import pytest | ||
@pytest.mark.subprocess() | ||
def test_pass(): | ||
assert True | ||
""" | ||
) | ||
file_name = os.path.basename(py_file.strpath) | ||
rec = self.inline_run(file_name) | ||
rec.assertoutcome(passed=1, failed=0, skipped=0) | ||
|
||
def test_subprocess_skip(self): | ||
""" | ||
Test a skipping test with subprocess decorator | ||
""" | ||
py_file = self.testdir.makepyfile( | ||
""" | ||
import pytest | ||
@pytest.mark.skip | ||
@pytest.mark.subprocess() | ||
def test_pass(): | ||
assert True | ||
""" | ||
) | ||
file_name = os.path.basename(py_file.strpath) | ||
rec = self.inline_run(file_name) | ||
rec.assertoutcome(passed=0, failed=0, skipped=1) |