Skip to content

Commit 921b1ee

Browse files
authored
Add testing doc (#618)
* Make some tweaks to tox and support 3.10 * Pass usedevelop to tox * Add dd_tags mark * Add testing doc * Tweaks * Add 3.10 to CI
1 parent 2fbded4 commit 921b1ee

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,12 @@ jobs:
3030
test:
3131
strategy:
3232
matrix:
33-
python-version: [3.6, 3.7, 3.8]
33+
python-version: ["3.6", "3.10"]
3434
platform: [ubuntu-latest, macos-latest] # windows-latest
3535
# test only latest version on macos and windows
3636
exclude:
3737
- platform: macos-latest
38-
python-version: 3.6
39-
- platform: macos-latest
40-
python-version: 3.7
38+
python-version: "3.6"
4139
# TODO enable once dd-trace-py is updated
4240
# - platform: windows-latest
4341
# python-version: 3.6

TESTING.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Running tests
2+
=============
3+
4+
The Datadog Python API client is mostly using BDD tests to verify its behaviro.
5+
They are using recodings to store HTTP interactions, allowing to run the tests without
6+
talking to the API. We also store the test time to be able to freeze.
7+
8+
You can control the behavior with the `RECORD` environment variable:
9+
- `RECORD=false`, the default value, means replaying HTTP requests from recordings.
10+
- `RECORD=true` creates or updates recordings. This will need valid credentials in `DD_TEST_CLIENT_API_KEY`
11+
and `DD_TEST_CLIENT_APP_KEY`.
12+
- `RECORD=none` ignores recordings. This will also runs tests that we call `integration-only`, i.e.
13+
tests that we don't record for security reasons. It also needs valid credentials.
14+
15+
Recording and freeze files are stored in the directory `tests/$VERSION/cassettes/test_scenarios/`
16+
17+
To run the tests, it's generally better to use a virtual environment. [tox](https://tox.wiki/) makes it easier to manage them.
18+
For example to run the tests for Python 3.9:
19+
20+
```shell
21+
tox -epy39
22+
```
23+
24+
To pass extra arguments to run the tests, you need to close `tox` arguments with `--`.
25+
You can get more verbose information with the `-v` flag to `pytest`, filter the tests using the `-k` or
26+
specifying the test full path. For example:
27+
28+
```shell
29+
tox -epy39 -- -k test_get_a_list_of_all_incident_teams_returns_ok_response -vvv
30+
```
31+
32+
`-k` takes a regular expression, so you don't have to specify the whole exact
33+
string. See https://docs.pytest.org/ for more information.
34+
35+
The first time you run a test that needs recordings, it will fail with:
36+
`Time file '$PATH/tests/$VERSION/cassettes/test_scenarios/$TEST_NAME.frozen' not found: create one setting 'RECORD=true' or ignore it using 'RECORD=none'`.

pytest.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[pytest]
2+
markers =
3+
dd_tags

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ classifiers=
2626
Programming Language :: Python :: 3.6
2727
Programming Language :: Python :: 3.7
2828
Programming Language :: Python :: 3.8
29+
Programming Language :: Python :: 3.9
30+
Programming Language :: Python :: 3.10
2931
project_urls =
3032
Bug Tracker = https://github.com/DataDog/datadog-api-client-python/issues
3133
Documentation = https://docs.datadoghq.com/api/

tox.ini

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
[tox]
2-
envlist = py36, py37, py38, docs
2+
envlist = py36, py37, py38, py39, py310, docs
33

44
[testenv]
5-
extras= tests
6-
commands=pytest
7-
5+
extras = tests
6+
commands = pytest {posargs}
7+
usedevelop = true
8+
skip_missing_interpreters = true
9+
passenv = *
810

911
[testenv:docs]
1012
skip_install = true
@@ -17,4 +19,4 @@ setenv =
1719
; See https://reproducible-builds.org/specs/source-date-epoch/
1820
SOURCE_DATE_EPOCH=1580601600
1921
commands =
20-
python -m mkdocs {posargs}
22+
python -m mkdocs {posargs}

0 commit comments

Comments
 (0)