Skip to content

Support deleting the database on start #265

@mmaslowskicc

Description

@mmaslowskicc

What action do you want to perform

I use postgresql_noproc and my tests crash with a segmentation fault in the code that I'm testing.

I attempt to rerun them to see if they fail again or to debug them.

What are the results

The tests database from previous run already exists and the fixture fails to create it:

>       with DatabaseJanitor(
                pg_user, pg_host, pg_port, pg_db, proc_fixture.version
        ):

../../.local/share/virtualenvs/venvname/lib/python3.8/site-packages/pytest_postgresql/factories.py:281: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../.local/share/virtualenvs/venvname/lib/python3.8/site-packages/pytest_postgresql/janitor.py:89: in __enter__
    self.init()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <pytest_postgresql.janitor.DatabaseJanitor object at 0x7ffff25220a0>

    def init(self) -> None:
        """Create database in postgresql."""
        with self.cursor() as cur:
>           cur.execute('CREATE DATABASE "{}";'.format(self.db_name))
E           psycopg2.errors.DuplicateDatabase: database "tests" already exists

../../.local/share/virtualenvs/venvname/lib/python3.8/site-packages/pytest_postgresql/janitor.py:55: DuplicateDatabase

What are the expected results

I somehow configure pytest-postgresql that it's not a mistake and it drops the test database before creating it, just like it would drop it at the end of the test.

Not dropping the database by default is good, since I could have accidentally configured it to use a more useful database with some data I want to keep.

Metadata

Metadata

Assignees

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