diff --git a/TESTING.md b/TESTING.md index 3d6536d6d..187bfb755 100644 --- a/TESTING.md +++ b/TESTING.md @@ -1,72 +1,37 @@ # Neo4j Driver Testing - To run driver tests, [Tox](https://tox.readthedocs.io) is required as well as at least one version of Python. -The versions of Python supported by this driver are CPython 3.7, 3.8, 3.9, and 3.10. +The versions of Python supported by this driver are CPython 3.7 - 3.12 +## Testing with TestKit +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. +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. +TestKit will take care of that for you and run many other tests as well. -## Unit Tests & Stub Tests +TestKit can be found here: https://github.com/neo4j-drivers/testkit. +See its README for more information on how to use it. -Unit tests and stub tests (those which make use of the [boltkit](https://github.com/neo4j-contrib/boltkit) stub server) can be run using: +## Unit Tests +Unit tests can be run using: ```bash -$ tox +tox -f unit ``` ## Integration Tests - -Each test run can also carry out integration tests against a specific version of Neo4j. -To enable integration tests, a server must be made available. -This can be either an existing server listening on the default Bolt port (7687) or a temporary installation from a particular package. -For example: -```bash -$ NEO4J_SERVER_PACKAGE=~/dist/neo4j-enterprise-3.1.1-unix.tar.gz tox -``` - -A web address can be provided as an alternative to a file path: -```bash -$ NEO4J_SERVER_PACKAGE=https://dist.neo4j.org/neo4j-enterprise-3.1.1-unix.tar.gz tox -``` - -If using an existing server, authentication details can be provided in a similar way: +Integration tests run against a real Neo4j server. +Hence, you must have a running server (either locally or remotely). +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. + +To allow the tests to connect to the server and choose the right tests to run, you must set the following environment variables: + * `TEST_NEO4J_HOST`: host name or IP address of the server (e.g., `localhost`) + * `TEST_NEO4J_PORT`: port number of the server (e.g., `7687`) + * `TEST_NEO4J_USER`: username for logging into server (e.g., `neo4j`) + * `TEST_NEO4J_PASS`: password for logging into server (e.g., `my-super-secret-p4$$w0rd`) + * `TEST_NEO4J_SCHEME`: with wich URL scheme to connect to the server (e.g., `bolt`, `neo4j+ssc`) + * `TEST_NEO4J_EDITION`: what edition the server is running (e.g., `enterprise`, `community`) + * `TEST_NEO4J_VERSION`: what version the server is running (e.g., `4.4.36`, `5.22.0`) + * `TEST_NEO4J_IS_CLUSTER`: whether the remote is a cluster or not (e.g., `true`/`1`, `false`/`0`) + +You can then run the integration tests with: ```bash -$ NEO4J_USER=bob NEO4J_PASSWORD=secret tox +tox -f integration ``` - - -## Code Coverage - -If [Coverage](https://coverage.readthedocs.io/) is installed, test runs automatically add data to a `.coverage` file. -To use this data, ensure that `coverage erase` is executed before commencing a test run; -a report can be viewed after the run with `coverage report --show-missing`. - -## Testing with Testkit - -Tests **require** the latest [Testkit 4.4](https://github.com/neo4j-drivers/testkit/tree/4.4), Python3 and Docker. - -Testkit is needed to be cloned and configured to run against the Python Driver. Use the following steps to configure Testkit. - -1. Clone the Testkit repository—preferably not inside this project's folder - -``` -git clone https://github.com/neo4j-drivers/testkit.git -``` - -2. Under the Testkit folder, install the requirements. - -``` -pip3 install -r requirements.txt -``` - -3. Define some enviroment variables to configure Testkit - -``` -export TEST_DRIVER_NAME=python -export TEST_DRIVER_REPO= -``` - -To run test against against some Neo4j version: - -``` -python3 main.py -``` - -More details about how to use Teskit could be found on [its repository](https://github.com/neo4j-drivers/testkit/tree/4.4) diff --git a/tests/conftest.py b/tests/conftest.py index 86a02441a..cdb70d462 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,8 +14,11 @@ # limitations under the License. +from __future__ import annotations + import asyncio import sys +import typing as t from functools import wraps import pytest @@ -132,9 +135,18 @@ def bolt_protocol_version(server_info): return server_info.protocol_version +def _parse_version(version: str) -> t.Tuple[float, ...]: + def parse_segment(seg: str) -> float: + if seg == "dev": + return float("inf") + return float(int(seg)) + + return tuple(map(parse_segment, version.split("."))) + + def mark_requires_min_bolt_version(version="3.5"): return pytest.mark.skipif( - env.NEO4J_VERSION < version, + _parse_version(env.NEO4J_VERSION) < _parse_version(version), reason=f"requires server version '{version}' or higher, " f"found '{env.NEO4J_VERSION}'" ) diff --git a/tests/env.py b/tests/env.py index b713d5b45..d9315612b 100644 --- a/tests/env.py +++ b/tests/env.py @@ -16,7 +16,6 @@ import abc import sys -import types import typing as t from os import environ