Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit dff264d

Browse files
ckunkiArBridgeman
andauthored
#157: Added instructions for (Re-)using an external or local databas… (#158)
Co-authored-by: Ariel Schulz <43442541+ArBridgeman@users.noreply.github.com>
1 parent 0bfbac4 commit dff264d

2 files changed

Lines changed: 81 additions & 22 deletions

File tree

pytest-backend/README.md

Lines changed: 79 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# pytest-exasol-backend Plugin
22

3-
The `pytest-exasol-backend` plugin is a collection of pytest fixtures commonly used for testing
4-
projects related to Exasol. In particular, it provides unified access to both Exasol On-Prem and
5-
SaaS backends. This eliminates the need to build different sets of tests for different backends.
3+
The pytest plugin `pytest-exasol-backend` provides pytest fixtures for using various Exasol database instances in integration tests.
4+
5+
In particular, the plugin enables accessing both Exasol On-Prem and SaaS backends in a unified way.
6+
7+
This enables your integration tests to use either backend variant without modification, incl. iterating the test for each backend variant.
68

79
## Features
810

@@ -19,10 +21,32 @@ The pytest-exasol-backend plugin can be installed using pip:
1921
pip install pytest-exasol-backend
2022
```
2123

24+
Alternatively via poetry, recommended as `dev` dependency:
25+
26+
```shell
27+
poetry add pytest-exasol-backend --group dev
28+
```
29+
2230
## Usage in Tests
2331

24-
Below is an example of a test that requires access to the database. Note, that by default
25-
this test will run twice - once for each backend.
32+
### PyExasol Connection
33+
34+
This test accesses the database via [PyExasol](github.com/exasol/pyexasol) and requires an additional (`dev`) dependency to `pyexasol` to be added to your project.
35+
36+
Note: If the pytest option `--backend all` is specified, then this test will run **twice** - once for each backend.
37+
38+
```python
39+
import pyexasol
40+
41+
def test_simple_sql(backend_aware_database_params):
42+
with pyexasol.connect(**backend_aware_database_params) as conn:
43+
value = conn.execute('SELECT 1 FROM DUAL').fetchval()
44+
assert value == 1
45+
```
46+
47+
The following test accesses a specific table within a database schema, and requires
48+
* Database schema `MY_SCHEMA` and table `MY_TABLE` to exist
49+
* Database table `MY_TABLE` to contain 5 rows
2650

2751
```python
2852
import pyexasol
@@ -33,8 +57,9 @@ def test_number_of_rows_in_my_table(backend_aware_database_params):
3357
assert num_of_rows == 5
3458
```
3559

36-
Here is an example of a test that requires access to the BucketFS. Again, this test will
37-
run for each backend, unless one of them is disabled in the CLI.
60+
### BucketFS
61+
62+
This test accesses the [BucketFS](https://docs.exasol.com/db/latest/database_concepts/bucketfs/bucketfs.htm). Again, this test will run for each backend, unless one of them is disabled in the CLI.
3863

3964
```python
4065
import exasol.bucketfs as bfs
@@ -45,8 +70,9 @@ def test_my_file_exists(backend_aware_bucketfs_params):
4570
assert my_bfs_file.exists()
4671
```
4772

48-
Sometimes it may be necessary to know which backend the test is running with. In such
49-
a case the `backend` fixture can be used, as in the example below.
73+
### Inspect the Selected Backend Variant
74+
75+
For inquiring the currenty selected backend variant in a test case, you can use the `backend` fixture, as shown below.
5076

5177
```python
5278
def test_something_backend_sensitive(backend):
@@ -60,35 +86,67 @@ def test_something_backend_sensitive(backend):
6086
raise RuntimeError(f'Unknown backend {backend}')
6187
```
6288

63-
## Selecting Backends in CLI
89+
## Selecting Backends on the Command Line
90+
91+
There is no default backend specified for testing.
92+
93+
Please use the `--backend` option to specify the target backend with either `onprem`, `saas`, or `all`.
94+
95+
The plugin automatically starts the selected backends and shuts them down after the test session has finished.
96+
* A SaaS backend is started via [saas-api-python](https://github.com/exasol/saas-api-python/).
97+
* An On-Prem backend via the [ITDE](https://github.com/exasol/integration-test-docker-environment).
98+
* Additionally you can [use an external or local database](#re-using-an-external-or-local-database).
99+
100+
Please noe that all selected backends are started preemptively, regardless of their _actual usage_ in tests.
101+
102+
Therefore, it is important to make sure the backends are not selected where they are not needed, for instance when running unit tests only.
103+
104+
### Example Command Lines
64105

65-
By default, none of the backends is selected for testing. Please use the `--backend` option to specify the target backend.
66-
The command below runs the tests on an on-prem database.
106+
Run the tests on an On-Prem database:
67107

68108
```shell
69109
pytest --backend=onprem my_test_suite.py
70110
```
71111

72-
This following command runs the test on two backends.
112+
Run the tests on two backends:
73113

74114
```shell
75115
pytest --backend=onprem --backend=saas my_test_suite.py
76116
```
77117

78-
The next command runs the test on all backends, which currently is equivalent to the previous command since there
79-
are only two backends available.
118+
Run the test on all backends&mdash;equivalent to the previous command:
80119

81120
```shell
82121
pytest --backend=all my_test_suite.py
83122
```
84123

85-
Please note that all selected backends starts preemptively, regardless of their actual usage in tests.
86-
Therefore, it is important to make sure the backends are not selected where they are not needed,
87-
for instance when running unit tests only.
124+
### (Re-)Using an External or Local Database
125+
126+
During development you can shorten the time between code changes and running the tests by (re-)using a backend that is already running.
127+
128+
To save 2-20 minutes each cycle, simply add CLI parameter `--itde-db-version=external`.
129+
130+
Alternatively, you can export environment variable `PYTEST_ADDOPTS`, e.g.
131+
```shell
132+
export PYTEST_ADDOPTS="--backend=onprem --itde-db-version=external"
133+
```
134+
135+
More parameters may be required if your setup deviates from the default values:
136+
137+
| Option | Default value |
138+
|-----------------------|------------------|
139+
| `--exasol-host` | `localhost` |
140+
| `--exasol-port` | `8563` |
141+
| `--exasol-username` | `sys` |
142+
| `--exasol-password` | `exasol` |
143+
| `--bucketfs-url` | `127.0.0.1:2580` |
144+
| `--bucketfs-username` | `w` |
145+
| `--bucketfs-password` | (none) |
88146

89-
## Setting ITDE parameters in CLI
147+
### Setting ITDE Parameters via CLI Options
90148

91-
Sometimes the default ITDE parameters cannot satisfy the test requirements. The plugin allows setting
149+
Sometimes, the default ITDE parameters cannot satisfy the test requirements. The plugin allows setting
92150
some of the parameters of the [api.spawn_test_environment(...)](https://github.com/exasol/integration-test-docker-environment/blob/92cc67b8f9ab78c52106c1c4ba19fe64811bcb2c/exasol_integration_test_docker_environment/lib/api/spawn_test_environment.py#L35)
93151
function. The parameter values can be provided in the CLI options. Currently, it is possible to set values of the following parameters:
94152
- `--itde-db-mem-size`
@@ -97,7 +155,7 @@ function. The parameter values can be provided in the CLI options. Currently, it
97155
- `--itde-additional-db-parameter`
98156
- `--itde-db-version`
99157

100-
In the example below the tests are run using an instance of the DockerDB with increased memory.
158+
This example runs the tests using an instance of the DockerDB with increased memory.
101159

102160
```shell
103161
pytest --backend=onprem --itde-db-mem-size "8 GiB" my_test_suite.py
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Unreleased
22

3-
## Internal
3+
## Refactorings
44

55
* #140: Ensured that a proper project-short-tag is used in SaaS tests.
66
* #141: Added a Merge Gate to the CI Workflow.
77
* #146: Relocked transitive dependency filelock
8+
* #150: Updated user guide and added instructions for (re-)using an external or local database to the `README`

0 commit comments

Comments
 (0)