Skip to content

Commit 73b731c

Browse files
author
Cecylia Borek
committed
update tests' README
1 parent 4857db7 commit 73b731c

File tree

1 file changed

+71
-33
lines changed

1 file changed

+71
-33
lines changed

tests/README.md

Lines changed: 71 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,88 @@
1-
# Splunk Test Suite
1+
# Python SDK tests
22

3-
The test suite uses Python's standard library and the built-in **unittest**
4-
library. The Splunk Enterprise SDK for Python has been tested with Python v3.7
5-
and v3.9.
3+
The tests use both Python's standard **unittest** library and **pytest**, and have been tested with Python 3.7, 3.9, and 3.13. The test suite can be executed across all supported Python versions using **tox**.
64

7-
To run the unit tests, open a command prompt in the **/splunk-sdk-python**
8-
directory and enter:
5+
## Test Types
96

10-
python setup.py test
7+
The SDK test suite is divided into three main types:
118

12-
You can also run individual test files, which are located in
13-
**/splunk-sdk-python/tests**. Each distinct area of the SDK is tested in a
14-
single file. For example, roles are tested
15-
in `test_role.py`. To run this test, open a command prompt in
16-
the **/splunk-sdk-python/tests** subdirectory and enter:
9+
1. [Unit Tests](./unit/)
1710

18-
python test_role.py
11+
- Fast and isolated, do not require a running Splunk instance
1912

20-
NOTE: Before running the test suite, make sure the instance of Splunk you
21-
are testing against doesn't have new events being dumped continuously
22-
into it. Several of the tests rely on a stable event count. It's best
23-
to test against a clean install of Splunk, but if you can't, you
24-
should at least disable the *NIX and Windows apps. Do not run the test
25-
suite against a production instance of Splunk! It will run just fine
26-
with the free Splunk license.
13+
2. [Integration Tests](./integration/)
2714

15+
- **Require a running Splunk instance**
16+
- Test SDK being used to communicate with a real Splunk instance via API
2817

29-
## Code Coverage
18+
3. [System Tests](./system/)
19+
- **Require a running Splunk instance**
20+
- Test SDK being used inside Splunk apps (SDK bundeled with apps inside Splunk instance)
21+
22+
## Setting up Splunk in Docker
23+
24+
Integration and system require a running test Splunk instance, which can be set up with Docker. Make sure Docker is installed and then start Splunk with:
25+
26+
```bash
27+
make up SPLUNK_VERSION=latest # runs docker compose up
28+
make wait_up # wait until the Splunk is ready
29+
```
30+
31+
If running on Mac, add this line to docker-compose:
32+
33+
```yaml
34+
architecture: linux/amd64
35+
```
3036
31-
Coverage.py is an excellent tool for measuring code coverage of Python programs.
37+
> **NOTE**: Before running the test suite, make sure the instance of Splunk you
38+
> are testing against doesn't have new events being dumped continuously
39+
> into it. Several of the tests rely on a stable event count. It's best
40+
> to test against a clean install of Splunk, but if you can't, you
41+
> should at least disable the \*NIX and Windows apps. **Do not run the test
42+
> suite against a production instance of Splunk!** It will run just fine
43+
> with the free Splunk license.
3244
33-
To install it, use easy_install:
45+
## Running tests with tox
3446
35-
easy_install coverage
47+
**tox** allows running tests across multiple Python versions and environments.
48+
The configurations are defined in the `tox.ini` file.
3649

37-
Or use pip:
50+
- Run all tests (unit, integration, and system) on all Python versions:
51+
```bash
52+
tox
53+
```
54+
- Run all unit tests on all Python versions:
3855

39-
pip install coverage
56+
```
57+
tox -f unit
58+
```
4059

41-
To generate a report of the code coverage of the unit test suite, open a command
42-
prompt in the **/splunk-sdk-python** directory and enter:
60+
- Run all unit tests on Python version currently active in your shell:
61+
62+
```
63+
tox -e unit
64+
```
65+
66+
- Run a specific type of test on a single Python version:
67+
68+
```bash
69+
tox -e py37-unit # example for Python 3.7 unit tests
70+
```
71+
72+
- Run a specific test file and Python version:
73+
```
74+
tox -e py39 -- tests/unit/test_utils.py
75+
```
76+
- Run a specific test method from a specific file and Python version:
77+
```
78+
tox -e py313 -- tests/system/test_csc_apps.py::TestEventingApp::test_metadata
79+
```
80+
81+
## Code Coverage
4382

44-
python setup.py coverage
83+
Code coverage is provided via `pytest-cov`, which uses `Coverage.py` under the hood.
84+
Coverage statistics are displayed at the end of each tox or pytest run.
4585

46-
This command runs the entire test suite and writes an HTML coverage report to
47-
the **/splunk-sdk-python/coverage_report** directory.
86+
## Test reports
4887

49-
For more information about Coverage.py, see the author's website
50-
([http://nedbatchelder.com/code/coverage/](http://nedbatchelder.com/code/coverage/)).
88+
Test reports are generated in JUnit XML format. For each tox environment, the reports are saved in: `test-reports/junit-{test-env}.xml`

0 commit comments

Comments
 (0)