Skip to content

create_postgres_fixture doesn't clean up after running tests. #202

@josiah-lunit

Description

@josiah-lunit

Describe the bug
After running tests using create_postgres_fixture, the created databases and templates are not removed upon completion. This leads to the buildup of old entries in an existing database at best and at worst causes errors if you try to change the configuration (due to existing old databases). I think after the test concludes (before the engine is finally disposed) it should clean up the templates and mock databases it created. At the very least, this behavior should be toggleable.

Environment

  • Host OS - MacOS
  • Docker image if applicable
  • Python Version - 3.12

To Reproduce
Steps to reproduce the behavior:

  1. Create and run a test using create_postgres_fixture using an existing running docker postgres database. Do this multiple times.
  2. Change the setting "template_database" to False
  3. Run your test, this time it will fail because of an existing database
  4. Change the setting "template_database" back to True
  5. Your tests will again fail because of an existing database
  6. Connect to the existing database using psql
  7. List the databases and see a multiple pytest_mock_resource_db_ databases.

Expected behavior
After running tests using an existing docker container, there should not be any remaining databases. Moreover, changing template_database back to True should not still fail.

Actual Behavior
Every test run creates new databases and they persist. Changing template_database back to True after running a Test with it at False causes a database already exists error.

Additional context
This problem only exists if you use an existing docker database instead of one generated by pytest mock resources.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions