Closed ckunki closed 5 months ago
Initially, I was thinking about adding an integration test for this feature.
Just like the other integration tests, this test would
--keep-saas-database
But then the outer test case needs to know either the unique name or ID of the database in order to
Passing the ID from inner test to outer test could be done via stdout and capsys
, for example.
Test code:
def test_keep_database(request, pytester, database_name, api_access, capsys):
testname = request.node.name
pytester.makepyfile(** _testfile(f"""
def {testname}(saas_database):
db = saas_database
print(f"\\ndatabase-id: {{db.id}}")
"""))
try:
result = pytester.runpytest("--keep-saas-database", "-s")
assert result.ret == pytest.ExitCode.OK
captured = capsys.readouterr()
id = None
for line in captured.out.splitlines():
if line.startswith("database-id: "):
id = line.split()[1]
finally:
if id:
api_access.delete_database(id)
But this also creates the risk that in case of an abnormal interruption or failure in the outer test, the database would continue to exist and create costs.
So after these thoughts I tend to not add such an integration test.
See https://github.com/exasol/saas-api-python/issues/13
Currently, there is already a command line option in pytest-saas. It only needs to be passed to
ApiAccess.database()
.