Skip to content

Testing ​

We use Pytest for testing with a mix of unit tests and integration tests.

Database Testing ​

We test against three databases to make sure everything works everywhere:

  • PostgreSQL - using testcontainers
  • MySQL - using testcontainers
  • SQLite - using temp files

We made a database_url fixture that runs each test against all three databases automatically, so we don't have to write separate tests for each one.

Test Setup ​

  • tests/init_db.py - Creates test database with users, employees, departments, skills, and projects
  • tests/conftest.py - Sets up the database fixtures

Test Types ​

Unit tests - Test individual functions:

  • test_query.py - Tests the query building functions
  • test_util.py - Tests utility functions
  • test_formatter.py - Tests output formatting
  • test_introspector.py - Tests database introspection

Integration tests - Test the full CLI app:

  • test_search.py - Tests search commands
  • test_inspect.py - Tests database inspection
  • test_output.py - Tests different output formats
  • test_basic.py - Tests that connecting to the database works

Dependencies ​

Dependencies for testing are in the dev group in pyproject.toml:

  • pytest - Testing framework
  • pytest-cov - Coverage reporting
  • testcontainers - Database containers

Coverage ​

Because of the large amount of tests, we're very proud that we maintain a test coverage above 80%.

Name                     Stmts   Miss  Cover
--------------------------------------------
dbgrep/__init__.py           2      0   100%
dbgrep/__main__.py         128     19    85%
dbgrep/formatter.py        117     38    68%
dbgrep/introspector.py      53      2    96%
dbgrep/multiconsole.py      19      1    95%
dbgrep/query.py             54      2    96%
dbgrep/util.py              23      0   100%
--------------------------------------------
TOTAL                      396     62    84%