simonw / db-to-sqlite

CLI tool for exporting tables or queries from any SQL database to a SQLite file
Apache License 2.0
370 stars 29 forks source link

Refactor unit tests to be parametrized against MySQL and PostgreSQL #13

Closed simonw closed 5 years ago

simonw commented 5 years ago

Something like this:

DATABASES = (
  ("MySQL", mysqldb),
  ("PostgreSQL", psycopg2)
)

@pytest.mark.parametrized("name,mod...):
def test_redact(name, mod):
    if mod is None:
          pytest.skip("Skipped {}".format(name))

I could define my own decorator which does the parameterized thing AND the fixture registration:

@test_databases
def test_redact(filepath, connection):
    # ...
simonw commented 5 years ago

I'm very happy with this:

https://github.com/simonw/db-to-sqlite/blob/3d450c00b5350bfd20606271c5fc1d6bc27bf556/tests/test_db_to_sqlite.py#L10-L15