From 0929bec26cbcae1797a10f7a6fce1bd4109351fb Mon Sep 17 00:00:00 2001 From: Jarrod Millman Date: Fri, 26 Aug 2022 04:33:48 -0700 Subject: [PATCH 1/2] Measure test coverage --- .github/workflows/coverage.yml | 31 +++++++++++++++++++++++++++++++ pyproject.toml | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 0000000..fad6c99 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,31 @@ +name: coverage + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + report: + runs-on: ubuntu-22.04 + strategy: + matrix: + python-version: ["3.10"] + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + + - name: Install packages + run: | + python -m pip install --upgrade pip wheel setuptools + python -m pip install ".[test]" + pip list + + - name: Test NetworkX + run: | + python -m pytest --cov=lazy_loader --doctest-modules --durations=20 + codecov diff --git a/pyproject.toml b/pyproject.toml index fcd0397..c64d578 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,7 @@ dynamic = ["description"] [project.optional-dependencies] -test = ["pytest >= 7"] +test = ["pytest >= 7.1", "pytest-cov >= 3.0", "codecov >= 2.1"] lint = ["pre-commit >= 2.20"] [project.urls] From 942f8d6204f82777f341f9ae9214fa46ca6102d8 Mon Sep 17 00:00:00 2001 From: Jarrod Millman Date: Sat, 27 Aug 2022 07:03:06 -0700 Subject: [PATCH 2/2] Fix --- .github/workflows/coverage.yml | 6 ++++-- lazy_loader/tests/__init__.py | 0 {tests => lazy_loader/tests}/fake_pkg/__init__.py | 0 {tests => lazy_loader/tests}/fake_pkg/__init__.pyi | 0 {tests => lazy_loader/tests}/fake_pkg/some_func.py | 0 {tests => lazy_loader/tests}/test_lazy_loader.py | 6 +++--- 6 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 lazy_loader/tests/__init__.py rename {tests => lazy_loader/tests}/fake_pkg/__init__.py (100%) rename {tests => lazy_loader/tests}/fake_pkg/__init__.pyi (100%) rename {tests => lazy_loader/tests}/fake_pkg/some_func.py (100%) rename {tests => lazy_loader/tests}/test_lazy_loader.py (96%) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index fad6c99..0d15840 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -25,7 +25,9 @@ jobs: python -m pip install ".[test]" pip list - - name: Test NetworkX + - name: Measure test coverage run: | - python -m pytest --cov=lazy_loader --doctest-modules --durations=20 + python -m pytest --cov=lazy_loader --durations=10 + # Tests fail if using `--doctest-modules`. I.e., + # python -m pytest --cov=lazy_loader --doctest-modules --durations=20 codecov diff --git a/lazy_loader/tests/__init__.py b/lazy_loader/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/fake_pkg/__init__.py b/lazy_loader/tests/fake_pkg/__init__.py similarity index 100% rename from tests/fake_pkg/__init__.py rename to lazy_loader/tests/fake_pkg/__init__.py diff --git a/tests/fake_pkg/__init__.pyi b/lazy_loader/tests/fake_pkg/__init__.pyi similarity index 100% rename from tests/fake_pkg/__init__.pyi rename to lazy_loader/tests/fake_pkg/__init__.pyi diff --git a/tests/fake_pkg/some_func.py b/lazy_loader/tests/fake_pkg/some_func.py similarity index 100% rename from tests/fake_pkg/some_func.py rename to lazy_loader/tests/fake_pkg/some_func.py diff --git a/tests/test_lazy_loader.py b/lazy_loader/tests/test_lazy_loader.py similarity index 96% rename from tests/test_lazy_loader.py rename to lazy_loader/tests/test_lazy_loader.py index b836078..800502a 100644 --- a/tests/test_lazy_loader.py +++ b/lazy_loader/tests/test_lazy_loader.py @@ -97,7 +97,7 @@ def test_lazy_attach(): def test_attach_same_module_and_attr_name(): - import fake_pkg + from lazy_loader.tests import fake_pkg # Grab attribute twice, to ensure that importing it does not # override function by module @@ -105,7 +105,7 @@ def test_attach_same_module_and_attr_name(): assert isinstance(fake_pkg.some_func, types.FunctionType) # Ensure imports from submodule still work - from fake_pkg.some_func import some_func + from lazy_loader.tests.fake_pkg.some_func import some_func assert isinstance(some_func, types.FunctionType) @@ -126,7 +126,7 @@ def test_stub_loading(tmp_path): def test_stub_loading_parity(): - import fake_pkg + from lazy_loader.tests import fake_pkg from_stub = lazy.attach_stub(fake_pkg.__name__, fake_pkg.__file__) stub_getter, stub_dir, stub_all = from_stub