Skip to content

Commit 035f7a4

Browse files
committed
docs: merge the test READMEs into tests/README.md
1 parent 32fa36e commit 035f7a4

4 files changed

Lines changed: 52 additions & 33 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ We use [ruff](https://docs.astral.sh/ruff/) for linting and formatting, [ty](htt
3030

3131
## Tests
3232

33-
- **Unit tests** (`tests/unit`) are isolated from the Apify API. See [`tests/unit/README.md`](tests/unit/README.md) for the rules they follow. Run them with `uv run poe unit-tests`, or a single test with `uv run pytest tests/unit/<path>.py::<test_name>`.
34-
- **Integration tests** (`tests/integration`) call the real Apify API. See [`tests/integration/README.md`](tests/integration/README.md) for the tokens they need. Run them with `uv run poe integration-tests`.
33+
[`tests/README.md`](tests/README.md) describes each test level, with its rules and required tokens.
34+
35+
- **Unit tests** (`tests/unit`) are isolated from the Apify API. Run them with `uv run poe unit-tests`, or a single test with `uv run pytest tests/unit/<path>.py::<test_name>`.
36+
- **Integration tests** (`tests/integration`) call the real Apify API. Run them with `uv run poe integration-tests`.
3537

3638
## Code style
3739

‎tests/README.md‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Tests
2+
3+
The tests have two levels:
4+
5+
- [Unit tests](#unit-tests) (`tests/unit`) are isolated from the Apify API.
6+
- [Integration tests](#integration-tests) (`tests/integration`) call the real Apify API.
7+
8+
A test that calls the Apify API is an integration test. Every other test is a unit test.
9+
10+
## Unit tests
11+
12+
Unit tests are fully isolated from the real Apify API. They use mocks, fakes, or a local HTTP test server, and they need no API tokens and no network access.
13+
14+
### Running unit tests
15+
16+
```bash
17+
uv run poe unit-tests
18+
```
19+
20+
### Mocking HTTP
21+
22+
Mock HTTP with the `httpserver` fixture from `pytest-httpserver`:
23+
24+
```python
25+
def test_example(httpserver: HTTPServer) -> None:
26+
httpserver.expect_request('/v2/endpoint').respond_with_json({'data': ...})
27+
client = ApifyClient(token='test', api_url=httpserver.url_for('/').removesuffix('/'))
28+
# assert client behavior
29+
```
30+
31+
## Integration tests
32+
33+
Integration tests communicate with the real Apify API.
34+
35+
### Running integration tests
36+
37+
The tests need valid API tokens in these environment variables:
38+
39+
- `APIFY_TEST_USER_API_TOKEN`
40+
- `APIFY_TEST_USER_2_API_TOKEN`, for the permission-related tests
41+
42+
```bash
43+
export APIFY_TEST_USER_API_TOKEN=<your-token>
44+
export APIFY_TEST_USER_2_API_TOKEN=<your-second-token>
45+
uv run poe integration-tests
46+
```
47+
48+
To run them against a different Apify API environment, also set `APIFY_INTEGRATION_TESTS_API_URL`.

‎tests/integration/README.md‎

Lines changed: 0 additions & 11 deletions
This file was deleted.

‎tests/unit/README.md‎

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)