Skip to content

Commit e5b2516

Browse files
authored
Add pytest-cov for unit-test coverage (#173)
1 parent 4737a71 commit e5b2516

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ __pycache__
1212
*.egg
1313
dist/
1414
build/
15+
.coverage
16+
htmlcov
1517

1618
.vscode
1719
.idea
1820
.DS_Store
1921

2022
docs/changelog.md
23+
24+
# default folder for memory storage data
25+
storage/

CONTRIBUTING.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,42 @@ and [direnv](https://github.com/direnv/direnv) to automatically activate/deactiv
2020

2121
## Dependencies
2222

23-
To install this package and its development dependencies, run `make install-dev`
23+
To install this package and its development dependencies, run `make install-dev`.
2424

25-
## Formatting
25+
## Code checking
2626

27-
We use `ruff` to automatically format the code to a common format. To run the formatting, just run `make format`.
27+
To run all our code checking tools together, just run `make check-code`.
2828

29-
## Linting, type-checking and unit testing
29+
### Linting
3030

31-
We use `ruff` for linting, `mypy` for type checking and `pytest` for unit testing. To run these tools, just run `make check-code`.
31+
We use [ruff](https://docs.astral.sh/ruff/) for linting to to analyze the code for potential issues and enforce
32+
uniformed code style. See the `pyproject.toml` for its configuration. To run the linting, just run `make lint`.
33+
34+
### Formatting
35+
36+
We use [ruff](https://docs.astral.sh/ruff/) for automated code formatting. It formats the code to follow uniformed
37+
code style and addresses auto-fixable linting issues. See the `pyproject.toml` for its configuration. To run
38+
the formatting, just run `make format`.
39+
40+
### Type checking
41+
42+
We use [mypy](https://mypy.readthedocs.io/en/stable/) for type checking. See the `mypy.ini` for its configuration.
43+
To run the type checking, just run `make type-check`.
44+
45+
### Unit tests
46+
47+
We use [pytest](https://docs.pytest.org/) as a testing framework with many plugins. See the `pyproject.toml` for
48+
both its configuration and the list of installed plugins. To run unit tests execute `make unit-tests`. To run unit
49+
tests with HTML coverage report execute `make unit-tests-cov`.
3250

3351
## Integration tests
3452

35-
We have integration tests which send API requests using the API client to the Apify Platform.
36-
To run these tests, you need to set the `APIFY_TEST_USER_API_TOKEN` environment variable to the API token of the Apify user you want to use for the tests,
37-
and then start them with `make integration-tests`.
53+
We have integration tests which build and run actors using the Python SDK on the Apify Platform. To run these tests,
54+
you need to set the `APIFY_TEST_USER_API_TOKEN` environment variable to the API token of the Apify user you want to
55+
use for the tests, and then start them with `make integration-tests`.
3856

39-
If you want to run the integration tests on a different environment than the main Apify Platform,
40-
you need to set the `APIFY_INTEGRATION_TESTS_API_URL` environment variable to the right URL to the Apify API you want to use.
57+
If you want to run the integration tests on a different environment than the main Apify Platform, you need to set
58+
the `APIFY_INTEGRATION_TESTS_API_URL` environment variable to the right URL to the Apify API you want to use.
4159

4260
## Documentation
4361

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ lint:
2626
python3 -m ruff check $(DIRS_WITH_CODE)
2727

2828
unit-tests:
29-
python3 -m pytest -n auto -ra tests/unit
29+
python3 -m pytest -n auto -ra tests/unit --cov=src/apify_client
30+
31+
unit-tests-cov:
32+
python3 -m pytest -n auto -ra tests/unit --cov=src/apify_client --cov-report=html
3033

3134
integration-tests:
3235
python3 -m pytest -n $(INTEGRATION_TESTS_CONCURRENCY) -ra tests/integration

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ dev = [
3838
"pydoc-markdown ~= 4.8.2",
3939
"pytest ~= 7.4.2",
4040
"pytest-asyncio ~= 0.21.0",
41+
"pytest-cov ~= 4.1.0",
4142
"pytest-only ~= 2.0.0",
4243
"pytest-timeout ~= 2.2.0",
4344
"pytest-xdist ~= 3.3.1",

0 commit comments

Comments
 (0)