-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make it possible to test span emission (#16)
- Loading branch information
Showing
5 changed files
with
67 additions
and
41 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
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,22 @@ | ||
import os | ||
import typing | ||
|
||
CIProviderT = typing.Literal["github_actions", "circleci"] | ||
|
||
|
||
def get_ci_provider() -> CIProviderT | None: | ||
if os.getenv("GITHUB_ACTIONS") == "true": | ||
return "github_actions" | ||
if os.getenv("CIRCLECI") == "true": | ||
return "circleci" | ||
return None | ||
|
||
|
||
def strtobool(string: str) -> bool: | ||
if string.lower() in {"y", "yes", "t", "true", "on", "1"}: | ||
return True | ||
|
||
if string.lower() in {"n", "no", "f", "false", "off", "0"}: | ||
return False | ||
|
||
raise ValueError(f"Could not convert '{string}' to boolean") |
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 |
---|---|---|
@@ -1,8 +1,7 @@ | ||
import pytest | ||
import os | ||
|
||
pytest_plugins = ["pytester"] | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def set_ci(monkeypatch: pytest.MonkeyPatch) -> None: | ||
monkeypatch.setenv("CI", "1") | ||
# Set this before we call any part of our plugin | ||
def pytest_cmdline_main() -> None: | ||
os.environ["CI"] = "1" | ||
os.environ["_PYTEST_MERGIFY_TEST"] = "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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import _pytest.pytester | ||
import _pytest.config | ||
|
||
|
||
def test_span( | ||
pytestconfig: _pytest.config.Config, | ||
) -> None: | ||
plugin = pytestconfig.pluginmanager.get_plugin("PytestMergify") | ||
assert plugin is not None | ||
assert plugin.exporter is not None | ||
spans = plugin.exporter.get_finished_spans() | ||
assert any(s.name == "pytestconfig setup" for s in spans) |