Skip to content

Commit 95477b9

Browse files
chore: speed up functional tests (#598)
* chore: speed up functional tests by installing `deptry` from wheel * chore: run functional tests in parallel * test: move arg types tests to unit * test: typo wheel path Co-authored-by: Florian Maas <[email protected]> * chore: single `test` command` --------- Co-authored-by: Florian Maas <[email protected]>
1 parent 7cf0aab commit 95477b9

18 files changed

+319
-151
lines changed

.github/workflows/main.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ jobs:
5353
- name: Check typing
5454
run: pdm run mypy
5555

56-
- name: Run tests
57-
run: pdm run pytest tests --cov --cov-config=pyproject.toml --cov-report=xml
56+
- name: Run unit tests
57+
run: pdm run pytest tests/unit --cov --cov-config=pyproject.toml --cov-report=xml
58+
59+
- name: Run functional tests
60+
run: pdm run pytest tests/functional -n auto --dist loadgroup
5861

5962
- name: Upload coverage reports to Codecov with GitHub Action on Python 3.11 and x86_64
6063
uses: codecov/codecov-action@v4
@@ -79,8 +82,11 @@ jobs:
7982
target: ${{ matrix.target }}
8083
python-target: ${{ matrix.target }}
8184

82-
- name: Run tests
83-
run: pdm run pytest tests --cov --cov-config=pyproject.toml --cov-report=xml
85+
- name: Run unit tests
86+
run: pdm run pytest tests/unit --cov --cov-config=pyproject.toml --cov-report=xml
87+
88+
- name: Run functional tests
89+
run: pdm run pytest tests/functional -n auto --dist loadgroup
8490

8591
macos:
8692
runs-on: macos-latest
@@ -99,8 +105,11 @@ jobs:
99105
target: ${{ matrix.target }}
100106
python-target: ${{ matrix.target == 'aarch64' && 'arm64' || 'x64' }}
101107

102-
- name: Run tests
103-
run: pdm run pytest tests --cov --cov-config=pyproject.toml --cov-report=xml
108+
- name: Run unit tests
109+
run: pdm run pytest tests/unit --cov --cov-config=pyproject.toml --cov-report=xml
110+
111+
- name: Run functional tests
112+
run: pdm run pytest tests/functional -n auto --dist loadgroup
104113

105114
check-docs:
106115
runs-on: ubuntu-latest

Makefile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,20 @@ check: ## Run code quality tools.
1515
@pdm run deptry python
1616

1717
.PHONY: test
18-
test: ## Test the code with pytest.
19-
@echo "🚀 Testing code: Running pytest"
20-
@pdm run pytest --cov --cov-config=pyproject.toml --cov-report=xml
18+
test: test-unit test-functional
19+
20+
.PHONY: test-unit
21+
test-unit: ## Run unit tests.
22+
@echo "🚀 Running unit tests"
23+
@pdm run pytest tests/unit
24+
25+
.PHONY: test-functional
26+
test-functional: ## Run functional tests.
27+
@echo "🚀 Running functional tests"
28+
@pdm run pytest tests/functional -n auto --dist loadgroup
2129

2230
.PHONY: build
23-
build: clean-build ## Build wheel and sdist files using PDM.
31+
build: ## Build wheel and sdist files using PDM.
2432
@echo "🚀 Creating wheel and sdist files"
2533
@maturin build
2634

docs/contributing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Ready to contribute? Here's how to set up _deptry_ for local development. Please
7979

8080
6. If you are adding a feature or fixing a bug, make sure to add tests in the `tests` directory.
8181

82-
7. Once you're done, validate that all unit tests are passing:
82+
7. Once you're done, validate that all unit and functional tests are passing:
8383
```bash
8484
make test
8585
```

pdm.lock

Lines changed: 175 additions & 117 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ dev = [
3434
"pre-commit==3.5.0",
3535
"pytest==8.1.1",
3636
"pytest-cov==4.1.0",
37+
"pytest-xdist[psutil]==3.5.0",
3738
]
3839
docs = [
3940
"mkdocs==1.5.3",

tests/functional/cli/test_cli.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44
from pathlib import Path
55
from typing import TYPE_CHECKING
66

7+
import pytest
78
from click.testing import CliRunner
89

910
from deptry.cli import deptry
11+
from tests.functional.utils import Project
1012
from tests.utils import get_issues_report, stylize
1113

1214
if TYPE_CHECKING:
1315
from tests.utils import PoetryVenvFactory
1416

1517

18+
@pytest.mark.xdist_group(name=Project.EXAMPLE)
1619
def test_cli_returns_error(poetry_venv_factory: PoetryVenvFactory) -> None:
17-
with poetry_venv_factory("example_project") as virtual_env:
20+
with poetry_venv_factory(Project.EXAMPLE) as virtual_env:
1821
issue_report = f"{uuid.uuid4()}.json"
1922
result = virtual_env.run(f"deptry . -o {issue_report}")
2023

@@ -71,8 +74,9 @@ def test_cli_returns_error(poetry_venv_factory: PoetryVenvFactory) -> None:
7174
]
7275

7376

77+
@pytest.mark.xdist_group(name=Project.EXAMPLE)
7478
def test_cli_ignore_notebooks(poetry_venv_factory: PoetryVenvFactory) -> None:
75-
with poetry_venv_factory("example_project") as virtual_env:
79+
with poetry_venv_factory(Project.EXAMPLE) as virtual_env:
7680
issue_report = f"{uuid.uuid4()}.json"
7781
result = virtual_env.run(f"deptry . --ignore-notebooks -o {issue_report}")
7882

@@ -141,22 +145,25 @@ def test_cli_ignore_notebooks(poetry_venv_factory: PoetryVenvFactory) -> None:
141145
]
142146

143147

148+
@pytest.mark.xdist_group(name=Project.EXAMPLE)
144149
def test_cli_ignore_flags(poetry_venv_factory: PoetryVenvFactory) -> None:
145-
with poetry_venv_factory("example_project") as virtual_env:
150+
with poetry_venv_factory(Project.EXAMPLE) as virtual_env:
146151
result = virtual_env.run("deptry . --per-rule-ignores DEP002=isort|pkginfo|requests -im white -id black")
147152

148153
assert result.returncode == 0
149154

150155

156+
@pytest.mark.xdist_group(name=Project.EXAMPLE)
151157
def test_cli_ignore_flag(poetry_venv_factory: PoetryVenvFactory) -> None:
152-
with poetry_venv_factory("example_project") as virtual_env:
158+
with poetry_venv_factory(Project.EXAMPLE) as virtual_env:
153159
result = virtual_env.run("deptry . --ignore DEP001,DEP002,DEP003,DEP004")
154160

155161
assert result.returncode == 0
156162

157163

164+
@pytest.mark.xdist_group(name=Project.EXAMPLE)
158165
def test_cli_exclude(poetry_venv_factory: PoetryVenvFactory) -> None:
159-
with poetry_venv_factory("example_project") as virtual_env:
166+
with poetry_venv_factory(Project.EXAMPLE) as virtual_env:
160167
issue_report = f"{uuid.uuid4()}.json"
161168
result = virtual_env.run(f"deptry . --exclude src/notebook.ipynb -o {issue_report}")
162169

@@ -225,8 +232,9 @@ def test_cli_exclude(poetry_venv_factory: PoetryVenvFactory) -> None:
225232
]
226233

227234

235+
@pytest.mark.xdist_group(name=Project.EXAMPLE)
228236
def test_cli_extend_exclude(poetry_venv_factory: PoetryVenvFactory) -> None:
229-
with poetry_venv_factory("example_project") as virtual_env:
237+
with poetry_venv_factory(Project.EXAMPLE) as virtual_env:
230238
issue_report = f"{uuid.uuid4()}.json"
231239
result = virtual_env.run(f"deptry . -ee src/notebook.ipynb -o {issue_report}")
232240

@@ -295,8 +303,9 @@ def test_cli_extend_exclude(poetry_venv_factory: PoetryVenvFactory) -> None:
295303
]
296304

297305

306+
@pytest.mark.xdist_group(name=Project.EXAMPLE)
298307
def test_cli_known_first_party(poetry_venv_factory: PoetryVenvFactory) -> None:
299-
with poetry_venv_factory("example_project") as virtual_env:
308+
with poetry_venv_factory(Project.EXAMPLE) as virtual_env:
300309
issue_report = f"{uuid.uuid4()}.json"
301310
result = virtual_env.run(f"deptry . --known-first-party white -o {issue_report}")
302311

@@ -341,8 +350,9 @@ def test_cli_known_first_party(poetry_venv_factory: PoetryVenvFactory) -> None:
341350
]
342351

343352

353+
@pytest.mark.xdist_group(name=Project.EXAMPLE)
344354
def test_cli_not_verbose(poetry_venv_factory: PoetryVenvFactory) -> None:
345-
with poetry_venv_factory("example_project") as virtual_env:
355+
with poetry_venv_factory(Project.EXAMPLE) as virtual_env:
346356
issue_report = f"{uuid.uuid4()}.json"
347357
result = virtual_env.run(f"deptry . -o {issue_report}")
348358

@@ -400,8 +410,9 @@ def test_cli_not_verbose(poetry_venv_factory: PoetryVenvFactory) -> None:
400410
]
401411

402412

413+
@pytest.mark.xdist_group(name=Project.EXAMPLE)
403414
def test_cli_verbose(poetry_venv_factory: PoetryVenvFactory) -> None:
404-
with poetry_venv_factory("example_project") as virtual_env:
415+
with poetry_venv_factory(Project.EXAMPLE) as virtual_env:
405416
issue_report = f"{uuid.uuid4()}.json"
406417
result = virtual_env.run(f"deptry . --verbose -o {issue_report}")
407418

@@ -459,8 +470,9 @@ def test_cli_verbose(poetry_venv_factory: PoetryVenvFactory) -> None:
459470
]
460471

461472

473+
@pytest.mark.xdist_group(name=Project.EXAMPLE)
462474
def test_cli_with_no_ansi(poetry_venv_factory: PoetryVenvFactory) -> None:
463-
with poetry_venv_factory("example_project") as virtual_env:
475+
with poetry_venv_factory(Project.EXAMPLE) as virtual_env:
464476
result = virtual_env.run("deptry . --no-ansi")
465477

466478
expected_output = [
@@ -480,8 +492,9 @@ def test_cli_with_no_ansi(poetry_venv_factory: PoetryVenvFactory) -> None:
480492
assert result.stderr == "\n".join(expected_output)
481493

482494

495+
@pytest.mark.xdist_group(name=Project.EXAMPLE)
483496
def test_cli_with_not_json_output(poetry_venv_factory: PoetryVenvFactory) -> None:
484-
with poetry_venv_factory("example_project") as virtual_env:
497+
with poetry_venv_factory(Project.EXAMPLE) as virtual_env:
485498
json_files_count = len(list(Path().glob("*.json")))
486499

487500
result = virtual_env.run("deptry .")
@@ -521,8 +534,9 @@ def test_cli_with_not_json_output(poetry_venv_factory: PoetryVenvFactory) -> Non
521534
assert result.stderr == "\n".join(expected_output)
522535

523536

537+
@pytest.mark.xdist_group(name=Project.EXAMPLE)
524538
def test_cli_with_json_output(poetry_venv_factory: PoetryVenvFactory) -> None:
525-
with poetry_venv_factory("example_project") as virtual_env:
539+
with poetry_venv_factory(Project.EXAMPLE) as virtual_env:
526540
issue_report = f"{uuid.uuid4()}.json"
527541
result = virtual_env.run(f"deptry . -o {issue_report}")
528542

tests/functional/cli/test_cli_gitignore.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
from pathlib import Path
55
from typing import TYPE_CHECKING
66

7+
import pytest
8+
9+
from tests.functional.utils import Project
710
from tests.utils import get_issues_report
811

912
if TYPE_CHECKING:
1013
from tests.utils import PipVenvFactory
1114

1215

16+
@pytest.mark.xdist_group(name=Project.GITIGNORE)
1317
def test_cli_gitignore_is_used(pip_venv_factory: PipVenvFactory) -> None:
14-
with pip_venv_factory("project_with_gitignore") as virtual_env:
18+
with pip_venv_factory(Project.GITIGNORE) as virtual_env:
1519
issue_report = f"{uuid.uuid4()}.json"
1620
result = virtual_env.run(f"deptry . -o {issue_report}")
1721

@@ -56,8 +60,9 @@ def test_cli_gitignore_is_used(pip_venv_factory: PipVenvFactory) -> None:
5660
]
5761

5862

63+
@pytest.mark.xdist_group(name=Project.GITIGNORE)
5964
def test_cli_gitignore_is_not_used(pip_venv_factory: PipVenvFactory) -> None:
60-
with pip_venv_factory("project_with_gitignore") as virtual_env:
65+
with pip_venv_factory(Project.GITIGNORE) as virtual_env:
6166
issue_report = f"{uuid.uuid4()}.json"
6267
result = virtual_env.run(f"deptry . --exclude build/|src/bar.py -o {issue_report}")
6368

tests/functional/cli/test_cli_multiple_source_directories.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
from pathlib import Path
55
from typing import TYPE_CHECKING
66

7+
import pytest
8+
9+
from tests.functional.utils import Project
710
from tests.utils import get_issues_report
811

912
if TYPE_CHECKING:
1013
from tests.utils import PipVenvFactory
1114

1215

16+
@pytest.mark.xdist_group(name=Project.MULTIPLE_SOURCE_DIRECTORIES)
1317
def test_cli_with_multiple_source_directories(pip_venv_factory: PipVenvFactory) -> None:
14-
with pip_venv_factory("project_with_multiple_source_directories") as virtual_env:
18+
with pip_venv_factory(Project.MULTIPLE_SOURCE_DIRECTORIES) as virtual_env:
1519
issue_report = f"{uuid.uuid4()}.json"
1620
result = virtual_env.run(f"deptry src worker -o {issue_report}")
1721

tests/functional/cli/test_cli_pdm.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
from pathlib import Path
55
from typing import TYPE_CHECKING
66

7+
import pytest
8+
9+
from tests.functional.utils import Project
710
from tests.utils import get_issues_report
811

912
if TYPE_CHECKING:
1013
from tests.utils import PDMVenvFactory
1114

1215

16+
@pytest.mark.xdist_group(name=Project.PDM)
1317
def test_cli_with_pdm(pdm_venv_factory: PDMVenvFactory) -> None:
14-
with pdm_venv_factory("project_with_pdm") as virtual_env:
18+
with pdm_venv_factory(Project.PDM) as virtual_env:
1519
issue_report = f"{uuid.uuid4()}.json"
1620
result = virtual_env.run(f"deptry . -o {issue_report}")
1721

tests/functional/cli/test_cli_pep_621.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
from pathlib import Path
55
from typing import TYPE_CHECKING
66

7+
import pytest
8+
9+
from tests.functional.utils import Project
710
from tests.utils import get_issues_report
811

912
if TYPE_CHECKING:
1013
from tests.utils import PipVenvFactory
1114

1215

16+
@pytest.mark.xdist_group(name=Project.PEP_621)
1317
def test_cli_with_pep_621(pip_venv_factory: PipVenvFactory) -> None:
14-
with pip_venv_factory("pep_621_project") as virtual_env:
18+
with pip_venv_factory(Project.PEP_621) as virtual_env:
1519
issue_report = f"{uuid.uuid4()}.json"
1620
result = virtual_env.run(f"deptry . -o {issue_report}")
1721

0 commit comments

Comments
 (0)