From 8d637abd8d9118fe8b986c108e5b861a20adf471 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Sat, 27 Apr 2024 13:27:00 +0100 Subject: [PATCH] improve coverage --- .github/workflows/main.yml | 2 +- pyproject.toml | 24 ++++++++++++++++++++++++ tests/test_testing.py | 9 ++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e5e7f838..10731490 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -97,7 +97,7 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} file: ./coverage.xml env_vars: PYTHON - - run: coverage report --precision=2 --fail-under=99 + - run: coverage report --fail-under=99 # https://github.com/marketplace/actions/alls-green#why used for branch protection checks check: diff --git a/pyproject.toml b/pyproject.toml index 8d9d96c2..105936bc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -200,3 +200,27 @@ filterwarnings = [ "ignore:The 'app' shortcut is now deprecated.*:DeprecationWarning:httpx*:", ] DJANGO_SETTINGS_MODULE = "tests.otel_integrations.django_test_project.django_test_site.settings" + +# https://coverage.readthedocs.io/en/latest/config.html#run +[tool.coverage.run] +branch = true + +# https://coverage.readthedocs.io/en/latest/config.html#report +[tool.coverage.report] +skip_covered = true +show_missing = true +ignore_errors = true +precision = 2 +exclude_lines = [ + 'def __repr__', + 'pragma: no cover', + 'raise NotImplementedError', + 'if TYPE_CHECKING:', + 'if typing.TYPE_CHECKING:', + '@overload', + '@typing.overload', + '\(Protocol\):$', + 'typing.assert_never', + 'assert_never', + 'if __name__ == .__main__.:', +] diff --git a/tests/test_testing.py b/tests/test_testing.py index 36800cf4..1eef8775 100644 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -1,7 +1,7 @@ import pytest import logfire -from logfire.testing import CaptureLogfire, TestExporter +from logfire.testing import CaptureLogfire, TestExporter, TimeGenerator def test_reset_exported_spans(exporter: TestExporter) -> None: @@ -77,3 +77,10 @@ def test_capfire_fixture(capfire: CaptureLogfire) -> None: ], }, ] + + +def test_time_generator(): + t = TimeGenerator() + assert t() == 1000000000 + assert t() == 2000000000 + assert repr(t) == 'TimeGenerator(ns_time=2000000000)'