Skip to main content

Conduct quality assurance testing on database tables

Project description

The SQL Test module assists in testing of data between SQL database tables. This is the development version of the module.

Use examples include comparing data in a view to those in a table derived from a star schema, or comparing results from a table derived from an external source to a table built via ETL.

Main Features

  • Class: SQLTest

    1. Creates and runs SQL database queries based on attributes provided with class instantiation or custom SQL query string.
    2. Completes five built in tests based on field-type categorizations of count, low_distinct, high_distinct, numeric, id_check.
    3. Flags fields above a specified difference threshold for "priority review".
    4. Displays a summary of results.
    5. Saves results and summary as specified.
  • Function: compare_tables

    1. Auto-detects the type of test to be run.
    2. Utilizes methods of SQLUnitTest to complete a full comparison of table values.
  • Function: sql_query

    1. Conducts basic database queries

Functionality Overview

The concept behind the testing is that database information can often be segmented by a field, such as dates. Testing can be done by comparing field values across these groupings.

If we had three tables rental_view, alt_rental_view, and alt_sim_rental_view we may wish to compare them to see if the "alt" tables are accurately capturing the information in rental_view.

Basic Query

We could view the tables:




Run Test Battery

And run tests on them:

To complete the test battery we need to determine the fields that can segment the data. In this case, the field that can be used to group the data is ss_dt for rental_view and alt_sim_rental_view, and ss_date for alt_rental_view.

Table information is specified on instantiation and compare_tables will create all query strings, gather the data, and run the tests based on the information provided. (Methods are available via SQLUnitTest to complete each step separately)

Setup Code

Activity, exceptions, and fields flagged for priority review are logged during operation.

Log Print-out

Log Storage

A summarized version of results (as a DataFrame or image), indicating the percentage difference between table fields (and the test type used), is also available via the test battery.

Visual Summary

Confirm Shared IDs

As further confirmation that are tables are replicas of each other, we may also test whether the IDs in one table are the same as the IDs in the other table.

We can use the .compare_ids method to compare between two tables at a time.



The files and provide examples of how the SQLAlchemy engines can be configured. These files should be customized for personal use.


This module utilizes:


Testing is completed using the PostgreSQL DVD Rental sample database.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for sql-test, version 0.1.2
Filename, size File type Python version Upload date Hashes
Filename, size sql_test-0.1.2-py3-none-any.whl (15.9 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size sql_test-0.1.2.tar.gz (16.2 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page