The Simplest Way to Make Looker and Pytest Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Pairing looker and pytest lets data teams test dashboards and queries before code goes live. The test runner calls the analytics API to check that data models return valid results. This workflow catches SQL errors and broken chart fields during continuous integration. Teams stop pushing bad changes to production dashboards. Users trust the numbers they see every day. How looker and pytest share data and keys The test script needs a way to log in to the analytics platform. Teams set up an API

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Pairing looker and pytest lets data teams test dashboards and queries before code goes live. The test runner calls the analytics API to check that data models return valid results.

This workflow catches SQL errors and broken chart fields during continuous integration. Teams stop pushing bad changes to production dashboards. Users trust the numbers they see every day.

How looker and pytest share data and keys

The test script needs a way to log in to the analytics platform. Teams set up an API key pair for the test runner to use. The runner sends those keys to get a short session token.

Once logged in, the test suite reads the project models and views. It runs checks against staging branches or pull requests. Each test asks the server to compile queries or run small data checks.

The analytics server then talks to the underlying data warehouse. It runs the generated SQL and sends the status back to the test tool. If a column is missing, the query fails right away. The test tool marks the build as failed and alerts the developer.

Data flows in both directions during a test run. The test runner sends branch names, query filters, and model names. The analytics app returns query results, row counts, and compiler error messages. Keeping this loop fast helps engineers fix bugs in minutes.

Common failure modes and how to scope roles

Many teams make the mistake of using an admin account for testing. A shared admin key has too much power across the whole system. Anyone who reads the build logs might grab that secret key. With an admin key, a bad script could delete production dashboards or change user roles.

End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Broad tokens also make auditing very hard for security teams. When ten developers trigger builds with one shared account, the logs look the same. You cannot tell which person or job ran a specific query. Unlogged queries hide who read sensitive tables during a test run.

To fix this, create a dedicated service role just for automated testing. Give this role read-only rights on the models it needs to check. Remove the right to manage users, change connections, or edit production spaces. The test runner only needs to switch branches and run validation checks.

You should also limit which database tables the test role can read. Point the test queries at small staging tables or synthetic data sets. If tests run against live tables, use data masking to rewrite sensitive fields. Masking rewrites emails, phone numbers, card numbers, and national IDs in the query results.

Network paths between the test runner and the analytics server need strict rules too. Lock down the API keys so they only work from known build server addresses. Rotate those keys on a regular schedule so old secrets expire fast. Good role scoping keeps your test pipeline safe and clean.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

What checks should we run in our test suite?

Start by running the built-in content validator and model compiler via the API. You can also write assertions that check row counts and null values in key views.

Should tests run against production data tables?

Running tests on smaller staging data is faster and lowers warehouse costs. If you must query live data, limit row counts and mask fields like emails or card numbers.

How do we keep test runs from slowing down deploys?

Only test the views and explores that changed in the current git branch. Running assertions in parallel across multiple worker nodes also cuts down wait times.

The query runs. The emails stay hidden.