Skip to content

Commit c85aa15

Browse files
authored
Emitting a warning instead of crashing (#388)
* Emitting a warning instead of crashing * Adding driver option
1 parent 2655257 commit c85aa15

1 file changed

Lines changed: 38 additions & 21 deletions

File tree

tests/conftest.py

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
from dataclasses import dataclass
23

34
import pytest
@@ -45,6 +46,7 @@ class GlobalData:
4546
secret: str = None
4647
root_password: str = None
4748
db_version: version = version.parse("0.0.0")
49+
crash: bool = False
4850

4951

5052
global_data = GlobalData()
@@ -69,6 +71,11 @@ def pytest_addoption(parser):
6971
parser.addoption(
7072
"--cluster", action="store_true", help="Run tests in a cluster setup"
7173
)
74+
parser.addoption(
75+
"--crash",
76+
action="store_true",
77+
help="Crashes the tests on API keyword (for debugging)",
78+
)
7279
parser.addoption(
7380
"--complete",
7481
action="store_true",
@@ -201,6 +208,7 @@ def pytest_configure(config):
201208
global_data.skip = config.getoption("skip")
202209
global_data.backup_path = config.getoption("backup_path")
203210
global_data.foxx_path = config.getoption("foxx_path")
211+
global_data.crash = config.getoption("crash")
204212

205213

206214
# noinspection PyShadowingNames
@@ -283,27 +291,6 @@ def pytest_generate_tests(metafunc):
283291
metafunc.parametrize("bad_db", bad_dbs)
284292

285293

286-
@pytest.fixture(autouse=True)
287-
def mock_formatters(monkeypatch):
288-
def mock_verify_format(body, result):
289-
body.pop("error", None)
290-
body.pop("code", None)
291-
result.pop("edge", None)
292-
293-
# Remove all None values
294-
# Sometimes they are expected to be excluded from the body (see computedValues)
295-
result = {k: v for k, v in result.items() if v is not None}
296-
body = {k: v for k, v in body.items() if v is not None}
297-
298-
if len(body) != len(result):
299-
before = sorted(body, key=lambda x: x.strip("_"))
300-
after = sorted(result, key=lambda x: x.strip("_"))
301-
raise ValueError(f"\nIN: {before}\nOUT: {after}")
302-
return result
303-
304-
monkeypatch.setattr(formatter, "verify_format", mock_verify_format)
305-
306-
307294
@pytest.fixture(autouse=False)
308295
def db_version():
309296
return global_data.db_version
@@ -489,3 +476,33 @@ def foxx_path():
489476
@pytest.fixture
490477
def skip_tests():
491478
return global_data.skip
479+
480+
481+
@pytest.fixture
482+
def crash_tests():
483+
return global_data.crash
484+
485+
486+
@pytest.fixture(autouse=True)
487+
def mock_formatters(monkeypatch, crash_tests):
488+
def mock_verify_format(body, result):
489+
body.pop("error", None)
490+
body.pop("code", None)
491+
result.pop("edge", None)
492+
493+
# Remove all None values
494+
# Sometimes they are expected to be excluded from the body (see computedValues)
495+
result = {k: v for k, v in result.items() if v is not None}
496+
body = {k: v for k, v in body.items() if v is not None}
497+
498+
if len(body) != len(result):
499+
before = sorted(body, key=lambda x: x.strip("_"))
500+
after = sorted(result, key=lambda x: x.strip("_"))
501+
if crash_tests:
502+
raise ValueError(f"\nIN: {before}\nOUT: {after}")
503+
else:
504+
warnings.warn(f"\nIN: {before}\nOUT: {after}")
505+
506+
return result
507+
508+
monkeypatch.setattr(formatter, "verify_format", mock_verify_format)

0 commit comments

Comments
 (0)