You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have integration tests which build and run Actors using the Python SDK on the Apify Platform.
5
-
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,
6
-
and then start them with `make integration-tests`.
3
+
We have integration tests which build and run Actors using the Python SDK on the Apify Platform. 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, and then start them with `make integration-tests`.
7
4
8
-
If you want to run the integration tests on a different environment than the main Apify Platform,
9
-
you need to set the `APIFY_INTEGRATION_TESTS_API_URL` environment variable to the right URL to the Apify API you want to use.
5
+
If you want to run the integration tests on a different environment than the main Apify Platform, you need to set the `APIFY_INTEGRATION_TESTS_API_URL` environment variable to the right URL to the Apify API you want to use.
10
6
11
-
How to write tests
12
-
------------------
7
+
## How to write tests
13
8
14
9
There are two fixtures which you can use to write tests:
15
10
16
11
### `apify_client_async`
17
12
18
-
This fixture just gives you an instance of `ApifyClientAsync` configured with the right token and API URL,
19
-
so you don't have to do that yourself.
13
+
This fixture just gives you an instance of `ApifyClientAsync` configured with the right token and API URL, so you don't have to do that yourself.
This fixture returns a factory function for creating Actors on the Apify Platform.
29
23
30
-
For the Actor source, the fixture takes the files from `tests/integration/actor_source_base`,
31
-
builds the Apify SDK wheel from the current codebase,
32
-
and adds the Actor source you passed to the fixture as an argument.
33
-
You have to pass exactly one of the `main_func`, `main_py` and `source_files` arguments.
24
+
For the Actor source, the fixture takes the files from `tests/integration/actor_source_base`, builds the Apify SDK wheel from the current codebase, and adds the Actor source you passed to the fixture as an argument. You have to pass exactly one of the `main_func`, `main_py` and `source_files` arguments.
34
25
35
-
The created Actor will be uploaded to the platform, built there, and after the test finishes, it will be automatically deleted.
36
-
If the Actor build fails, it will not be deleted, so that you can check why the build failed.
26
+
The created Actor will be uploaded to the platform, built there, and after the test finishes, it will be automatically deleted. If the Actor build fails, it will not be deleted, so that you can check why the build failed.
37
27
38
28
### Creating test Actor straight from a Python function
39
29
40
-
You can create Actors straight from a Python function.
41
-
This is great because you can have the test Actor source code checked with the linter.
30
+
You can create Actors straight from a Python function. This is great because you can have the test Actor source code checked with the linter.
actor =await make_actor('something', main_func=main)
41
+
actor =await make_actor(label='something', main_func=main)
42
+
run_result =await run_actor(actor)
50
43
51
-
run_result =await actor.call()
52
-
53
-
assert run_result isnotNone
54
-
assert run_result['status'] =='SUCCEEDED'
44
+
assert run_result.status =='SUCCEEDED'
55
45
```
56
46
57
-
These Actors will have the `src/main.py` file set to the `main` function definition,
58
-
prepended with `import asyncio` and `from apify import Actor`, for your convenience.
47
+
These Actors will have the `src/main.py` file set to the `main` function definition, prepended with `import asyncio` and `from apify import Actor`, for your convenience.
59
48
60
49
You can also pass extra imports directly to the main function:
actor =await make_actor('something', main_func=main)
72
-
73
-
run_result =await actor.call()
63
+
actor =await make_actor(label='something', main_func=main)
64
+
run_result =await run_actor(actor)
74
65
75
-
assert run_result isnotNone
76
-
assert run_result['status'] =='SUCCEEDED'
66
+
assert run_result.status =='SUCCEEDED'
77
67
```
78
68
79
69
### Creating Actor from source files
80
70
81
-
You can also pass the source files directly if you need something more complex
82
-
(e.g. pass some fixed value to the Actor source code or use multiple source files).
71
+
You can also pass the source files directly if you need something more complex (e.g. pass some fixed value to the Actor source code or use multiple source files).
83
72
84
73
To pass the source code of the `src/main.py` file directly, use the `main_py` argument to `make_actor`:
0 commit comments