Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment with fixtures #41

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f8fd36a
#37 Added the pytest-backend project
ahsimb Aug 2, 2024
95427af
#37 Added the pytest-backend project
ahsimb Aug 2, 2024
6d161ea
#37 Added the pytest-backend project
ahsimb Aug 2, 2024
ea57811
#37 Running only itde tests
ahsimb Aug 5, 2024
c1ac5e6
#37 Restored pytest-itde as it was
ahsimb Aug 5, 2024
582fbb8
#37 Improved readability of parameterized test
ahsimb Aug 5, 2024
dfb6612
#37 Made all fixtures the session level
ahsimb Aug 6, 2024
ebb0a88
Update .gitattributes
ckunki Aug 6, 2024
70a3114
#37 Changed dependencies on other plugins to released versions
ahsimb Aug 6, 2024
62548bc
Update justfile
ahsimb Aug 6, 2024
00f4128
Merge branch 'main' into feature/37-backend-project
ahsimb Aug 6, 2024
fabfe78
Merge remote-tracking branch 'origin/feature/37-backend-project' into…
ahsimb Aug 6, 2024
43c92be
#37 referencing pytest-exasol-saas 0.2.2
ahsimb Aug 6, 2024
ba96511
Added fixture debugging
ahsimb Aug 7, 2024
2318770
Improved debugging
ahsimb Aug 7, 2024
fc77072
Added test for a disabled backend
ahsimb Aug 7, 2024
a31be4a
Added test for a disabled backend
ahsimb Aug 7, 2024
c92b781
Added test for a disabled backend
ahsimb Aug 7, 2024
206cdc9
Added test for a disabled backend
ahsimb Aug 7, 2024
b40a162
Added test for a disabled backend
ahsimb Aug 7, 2024
3c5fc76
Created another test file
ahsimb Aug 7, 2024
4db4407
Created another test file
ahsimb Aug 7, 2024
0daa346
Adding plugins directly
ahsimb Aug 7, 2024
5d79498
Merge branch 'main' into experiment_with_fixtures
ahsimb Aug 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PROJECTS := "pytest-backend pytest-saas pytest-itde"
PROJECTS := "pytest-backend"

# Default target
default:
Expand Down
37 changes: 23 additions & 14 deletions pytest-backend/exasol/pytest_backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
_BACKEND_ONPREM = 'onprem'
_BACKEND_SAAS = 'saas'

_onprem_stash_key = pytest.StashKey[bool]()
_saas_stash_key = pytest.StashKey[bool]()
itde_calls = 0
saas_calls = 0


def pytest_addoption(parser):
Expand Down Expand Up @@ -62,19 +62,18 @@ def use_saas(request) -> bool:


@pytest.fixture(scope="session")
def backend_aware_onprem_database(request,
use_onprem,
def backend_aware_onprem_database(use_onprem,
itde_config,
exasol_config,
bucketfs_config,
ssh_config,
database_name) -> None:
if use_onprem and (itde_config.db_version != "external"):
# Guard against a potential issue with repeated call of a parameterised fixture
if _onprem_stash_key in request.session.stash:
raise RuntimeError(('Repeated call of the session level fixture '
'backend_aware_onprem_database'))
request.session.stash[_onprem_stash_key] = True
global itde_calls
itde_calls += 1
print('-----------------')
print('| STARTING ITDE |')
print('-----------------')

bucketfs_url = urlparse(bucketfs_config.url)
_, cleanup_function = api.spawn_test_environment(
Expand All @@ -99,11 +98,11 @@ def backend_aware_saas_database_id(request,
saas_pat,
saas_account_id) -> str:
if use_saas:
# Guard against a potential issue with repeated call of a parameterised fixture
if _saas_stash_key in request.session.stash:
raise RuntimeError(('Repeated call of the session level fixture '
'backend_aware_saas_database_id'))
request.session.stash[_saas_stash_key] = True
global saas_calls
saas_calls += 1
print('-----------------')
print('| STARTING ITDE |')
print('-----------------')

db_id = request.config.getoption("--saas-database-id")
keep = request.config.getoption("--keep-saas-database")
Expand Down Expand Up @@ -228,3 +227,13 @@ def backend_aware_bucketfs_params(backend,
return backend_aware_saas_bucketfs_params
else:
ValueError(f'Unknown backend {backend}')


@pytest.fixture
def global_itde_calls() -> int:
return itde_calls


@pytest.fixture
def global_saas_calls() -> int:
return saas_calls
57 changes: 53 additions & 4 deletions pytest-backend/test/integration/pytest_backend_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from textwrap import dedent
import re
import pytest

import pyexasol
import exasol.bucketfs as bfs

from exasol.pytest_backend import *

pytest_plugins = ["pytester"]


Expand Down Expand Up @@ -62,16 +63,64 @@ def test_pass_options_via_cli(pytester, test_case, cli_args, num_passed, num_ski
result.assert_outcomes(passed=num_passed, skipped=num_skipped)


def test_backend_aware_database_params(backend_aware_database_params):
def test_backend_aware_database_params1(backend_aware_database_params, global_itde_calls, global_saas_calls):
conn = pyexasol.connect(**backend_aware_database_params)
res = conn.execute('SELECT SESSION_ID FROM SYS.EXA_ALL_SESSIONS;').fetchall()
assert res
assert global_itde_calls <= 1
assert global_saas_calls <= 1
assert global_itde_calls + global_saas_calls > 0


def test_backend_aware_database_params2(backend_aware_database_params, global_itde_calls, global_saas_calls):
conn = pyexasol.connect(**backend_aware_database_params)
res = conn.execute('SELECT SESSION_ID FROM SYS.EXA_ALL_SESSIONS;').fetchall()
assert res
assert global_itde_calls <= 1
assert global_saas_calls <= 1
assert global_itde_calls + global_saas_calls > 0


def test_backend_aware_database_params3(backend_aware_database_params, global_itde_calls, global_saas_calls):
conn = pyexasol.connect(**backend_aware_database_params)
res = conn.execute('SELECT SESSION_ID FROM SYS.EXA_ALL_SESSIONS;').fetchall()
assert res
assert global_itde_calls <= 1
assert global_saas_calls <= 1
assert global_itde_calls + global_saas_calls > 0


def test_backend_aware_bucketfs_params1(backend_aware_bucketfs_params, global_itde_calls, global_saas_calls):
bfs_path = bfs.path.build_path(**backend_aware_bucketfs_params, path='plugin_test1')
file_content = b'In God We Trust'
bfs_path.write(file_content)
data_back = b''.join(bfs_path.read())
bfs_path.rm()
assert data_back == file_content
assert global_itde_calls <= 1
assert global_saas_calls <= 1
assert global_itde_calls + global_saas_calls > 0


def test_backend_aware_bucketfs_params2(backend_aware_bucketfs_params, global_itde_calls, global_saas_calls):
bfs_path = bfs.path.build_path(**backend_aware_bucketfs_params, path='plugin_test2')
file_content = b'In God We Trust'
bfs_path.write(file_content)
data_back = b''.join(bfs_path.read())
bfs_path.rm()
assert data_back == file_content
assert global_itde_calls <= 1
assert global_saas_calls <= 1
assert global_itde_calls + global_saas_calls > 0


def test_backend_aware_bucketfs_params(backend_aware_bucketfs_params):
bfs_path = bfs.path.build_path(**backend_aware_bucketfs_params, path='plugin_test')
def test_backend_aware_bucketfs_params3(backend_aware_bucketfs_params, global_itde_calls, global_saas_calls):
bfs_path = bfs.path.build_path(**backend_aware_bucketfs_params, path='plugin_test3')
file_content = b'In God We Trust'
bfs_path.write(file_content)
data_back = b''.join(bfs_path.read())
bfs_path.rm()
assert data_back == file_content
assert global_itde_calls <= 1
assert global_saas_calls <= 1
assert global_itde_calls + global_saas_calls > 0
67 changes: 67 additions & 0 deletions pytest-backend/test/integration/test2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import pyexasol
import exasol.bucketfs as bfs

from exasol.pytest_backend import *


def test_backend_aware_database_params11(backend_aware_database_params, global_itde_calls, global_saas_calls):
conn = pyexasol.connect(**backend_aware_database_params)
res = conn.execute('SELECT SESSION_ID FROM SYS.EXA_ALL_SESSIONS;').fetchall()
assert res
assert global_itde_calls <= 1
assert global_saas_calls <= 1
assert global_itde_calls + global_saas_calls > 0


def test_backend_aware_database_params12(backend_aware_database_params, global_itde_calls, global_saas_calls):
conn = pyexasol.connect(**backend_aware_database_params)
res = conn.execute('SELECT SESSION_ID FROM SYS.EXA_ALL_SESSIONS;').fetchall()
assert res
assert global_itde_calls <= 1
assert global_saas_calls <= 1
assert global_itde_calls + global_saas_calls > 0


def test_backend_aware_database_params13(backend_aware_database_params, global_itde_calls, global_saas_calls):
conn = pyexasol.connect(**backend_aware_database_params)
res = conn.execute('SELECT SESSION_ID FROM SYS.EXA_ALL_SESSIONS;').fetchall()
assert res
assert global_itde_calls <= 1
assert global_saas_calls <= 1
assert global_itde_calls + global_saas_calls > 0


def test_backend_aware_bucketfs_params11(backend_aware_bucketfs_params, global_itde_calls, global_saas_calls):
bfs_path = bfs.path.build_path(**backend_aware_bucketfs_params, path='plugin_test1')
file_content = b'In God We Trust'
bfs_path.write(file_content)
data_back = b''.join(bfs_path.read())
bfs_path.rm()
assert data_back == file_content
assert global_itde_calls <= 1
assert global_saas_calls <= 1
assert global_itde_calls + global_saas_calls > 0


def test_backend_aware_bucketfs_params12(backend_aware_bucketfs_params, global_itde_calls, global_saas_calls):
bfs_path = bfs.path.build_path(**backend_aware_bucketfs_params, path='plugin_test2')
file_content = b'In God We Trust'
bfs_path.write(file_content)
data_back = b''.join(bfs_path.read())
bfs_path.rm()
assert data_back == file_content
assert global_itde_calls <= 1
assert global_saas_calls <= 1
assert global_itde_calls + global_saas_calls > 0


def test_backend_aware_bucketfs_params13(backend_aware_bucketfs_params, global_itde_calls, global_saas_calls):
bfs_path = bfs.path.build_path(**backend_aware_bucketfs_params, path='plugin_test3')
file_content = b'In God We Trust'
bfs_path.write(file_content)
data_back = b''.join(bfs_path.read())
bfs_path.rm()
assert data_back == file_content
assert global_itde_calls <= 1
assert global_saas_calls <= 1
assert global_itde_calls + global_saas_calls > 0
Loading