Skip to content

Commit deac960

Browse files
authored
Update testing docs (#1081)
1 parent 4fbf12b commit deac960

File tree

3 files changed

+39
-63
lines changed

3 files changed

+39
-63
lines changed

TESTING.md

Lines changed: 26 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,37 @@
11
# Neo4j Driver Testing
2-
32
To run driver tests, [Tox](https://tox.readthedocs.io) is required as well as at least one version of Python.
4-
The versions of Python supported by this driver are CPython 3.7, 3.8, 3.9, and 3.10.
3+
The versions of Python supported by this driver are CPython 3.7 - 3.12
54

5+
## Testing with TestKit
6+
TestKit is the shared test suite used by all official (and some community contributed) Neo4j drivers to ensure consistent and correct behavior across all drivers.
7+
When using TestKit to run tests, you don't have to take care of manually setting up or running unit tests or integration tests as shown below.
8+
TestKit will take care of that for you and run many other tests as well.
69

7-
## Unit Tests & Stub Tests
10+
TestKit can be found here: https://github.com/neo4j-drivers/testkit.
11+
See its README for more information on how to use it.
812

9-
Unit tests and stub tests (those which make use of the [boltkit](https://github.com/neo4j-contrib/boltkit) stub server) can be run using:
13+
## Unit Tests
14+
Unit tests can be run using:
1015
```bash
11-
$ tox
16+
tox -f unit
1217
```
1318

1419
## Integration Tests
15-
16-
Each test run can also carry out integration tests against a specific version of Neo4j.
17-
To enable integration tests, a server must be made available.
18-
This can be either an existing server listening on the default Bolt port (7687) or a temporary installation from a particular package.
19-
For example:
20-
```bash
21-
$ NEO4J_SERVER_PACKAGE=~/dist/neo4j-enterprise-3.1.1-unix.tar.gz tox
22-
```
23-
24-
A web address can be provided as an alternative to a file path:
25-
```bash
26-
$ NEO4J_SERVER_PACKAGE=https://dist.neo4j.org/neo4j-enterprise-3.1.1-unix.tar.gz tox
27-
```
28-
29-
If using an existing server, authentication details can be provided in a similar way:
20+
Integration tests run against a real Neo4j server.
21+
Hence, you must have a running server (either locally or remotely).
22+
Make sure there's no data in any of the DBMS's databases and that an empty database `neo4j` is available and is set as the default database.
23+
24+
To allow the tests to connect to the server and choose the right tests to run, you must set the following environment variables:
25+
* `TEST_NEO4J_HOST`: host name or IP address of the server (e.g., `localhost`)
26+
* `TEST_NEO4J_PORT`: port number of the server (e.g., `7687`)
27+
* `TEST_NEO4J_USER`: username for logging into server (e.g., `neo4j`)
28+
* `TEST_NEO4J_PASS`: password for logging into server (e.g., `my-super-secret-p4$$w0rd`)
29+
* `TEST_NEO4J_SCHEME`: with wich URL scheme to connect to the server (e.g., `bolt`, `neo4j+ssc`)
30+
* `TEST_NEO4J_EDITION`: what edition the server is running (e.g., `enterprise`, `community`)
31+
* `TEST_NEO4J_VERSION`: what version the server is running (e.g., `4.4.36`, `5.22.0`)
32+
* `TEST_NEO4J_IS_CLUSTER`: whether the remote is a cluster or not (e.g., `true`/`1`, `false`/`0`)
33+
34+
You can then run the integration tests with:
3035
```bash
31-
$ NEO4J_USER=bob NEO4J_PASSWORD=secret tox
36+
tox -f integration
3237
```
33-
34-
35-
## Code Coverage
36-
37-
If [Coverage](https://coverage.readthedocs.io/) is installed, test runs automatically add data to a `.coverage` file.
38-
To use this data, ensure that `coverage erase` is executed before commencing a test run;
39-
a report can be viewed after the run with `coverage report --show-missing`.
40-
41-
## Testing with Testkit
42-
43-
Tests **require** the latest [Testkit 4.4](https://github.com/neo4j-drivers/testkit/tree/4.4), Python3 and Docker.
44-
45-
Testkit is needed to be cloned and configured to run against the Python Driver. Use the following steps to configure Testkit.
46-
47-
1. Clone the Testkit repository—preferably not inside this project's folder
48-
49-
```
50-
git clone https://github.com/neo4j-drivers/testkit.git
51-
```
52-
53-
2. Under the Testkit folder, install the requirements.
54-
55-
```
56-
pip3 install -r requirements.txt
57-
```
58-
59-
3. Define some enviroment variables to configure Testkit
60-
61-
```
62-
export TEST_DRIVER_NAME=python
63-
export TEST_DRIVER_REPO=<path for the root folder of driver repository>
64-
```
65-
66-
To run test against against some Neo4j version:
67-
68-
```
69-
python3 main.py
70-
```
71-
72-
More details about how to use Teskit could be found on [its repository](https://github.com/neo4j-drivers/testkit/tree/4.4)

tests/conftest.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
# limitations under the License.
1515

1616

17+
from __future__ import annotations
18+
1719
import asyncio
1820
import sys
21+
import typing as t
1922
from functools import wraps
2023

2124
import pytest
@@ -132,9 +135,18 @@ def bolt_protocol_version(server_info):
132135
return server_info.protocol_version
133136

134137

138+
def _parse_version(version: str) -> t.Tuple[float, ...]:
139+
def parse_segment(seg: str) -> float:
140+
if seg == "dev":
141+
return float("inf")
142+
return float(int(seg))
143+
144+
return tuple(map(parse_segment, version.split(".")))
145+
146+
135147
def mark_requires_min_bolt_version(version="3.5"):
136148
return pytest.mark.skipif(
137-
env.NEO4J_VERSION < version,
149+
_parse_version(env.NEO4J_VERSION) < _parse_version(version),
138150
reason=f"requires server version '{version}' or higher, "
139151
f"found '{env.NEO4J_VERSION}'"
140152
)

tests/env.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import abc
1818
import sys
19-
import types
2019
import typing as t
2120
from os import environ
2221

0 commit comments

Comments
 (0)