exasol/pytest-plugins

Implement keep alive for saas-database

Closed this issue · 1 comments

See exasol/saas-api-python#13

Currently, there is already a command line option in pytest-saas.
It only needs to be passed to ApiAccess.database().

Initially, I was thinking about adding an integration test for this feature.

Just like the other integration tests, this test would

  • create an inner test case
  • let pytester execute it with command line option --keep-saas-database

But then the outer test case needs to know either the unique name or ID of the database in order to

  • verify the DB still exists after inner pytest has terminated.
  • to finally delete the DB as the inner test requested to keep it

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.