diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 0000000..0d15840 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,33 @@ +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: Measure test coverage + run: | + 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 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]