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

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams use cypress and pytest together to test full web apps from back to front. Pytest checks backend code and sets up test data, while Cypress runs browser tests. This pair lets each tool do what it does best in one pipeline. Python scripts handle data setup and API checks fast. Then browser scripts test the real user screen. How permissions and data flow between cypress and pytest In a standard pipeline, one runner starts both tools in a clear order. Pytest often runs first to check API ru

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.

Teams use cypress and pytest together to test full web apps from back to front. Pytest checks backend code and sets up test data, while Cypress runs browser tests.

This pair lets each tool do what it does best in one pipeline. Python scripts handle data setup and API checks fast. Then browser scripts test the real user screen.

How permissions and data flow between cypress and pytest

In a standard pipeline, one runner starts both tools in a clear order. Pytest often runs first to check API rules and seed the database. It logs in to the test database with a scoped role. It writes fresh rows for users, orders, or items. Then it saves those new record IDs to a shared file or local service.

Next, Cypress reads that shared state to start its browser checks. It uses the seeded user accounts to log in through the web screen. When Cypress clicks buttons on the page, the app talks to the backend. After the browser run finishes, Pytest can run again to clean up test rows.

Both tools need keys to talk to the app and the database. Good pipelines keep these keys in secret stores. The runner reads the keys and passes them to each test step. Each tool only gets the keys it needs for its own job.

Common failure modes and how to scope roles

Many teams make the mistake of sharing one admin account across both tools. When Cypress and Pytest use the same wide database key, bad things happen. A bug in a browser test might wipe out tables needed by API tests. Broad tokens also make it hard to see which tool changed a row.

Unlogged queries are another big problem in shared test setups. When both tools hit the database at once, tests can fail at random. If you do not log each query by tool name, you cannot find the clash. You waste hours trying to fix a test that only fails in the pipeline.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

To fix this, give each tool its own role and network path. Give Pytest a role that can write test data in specific schemas only. Give Cypress no direct database key at all. Instead, let Cypress call backend API routes to change state during a browser test.

If Cypress must trigger data setup, have it call a small local helper service. That service can run the Python setup logic with the right database role. Also, keep test runs isolated by giving each worker its own schema or user prefix. This stops parallel runs from stepping on each other.

Managing test data privacy in shared pipelines

Test suites often fail audits because teams copy real user data into test databases. When Pytest seeds data or Cypress reads screens, real details can leak into logs. Screenshots and test reports might save raw emails, phone numbers, or card numbers.

Always use fake data when Pytest builds test rows for Cypress. If you must query shared staging data, use data masking on those fields. Masking rewrites matched fields like national IDs, emails, and card numbers in query results. This keeps sensitive details out of your test logs and browser snapshots.

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

Should Cypress or Pytest run first in a build pipeline?

Run Pytest first to check fast backend unit and API tests. If those pass, use Pytest fixtures to seed data and run Cypress browser tests next.

How should Cypress trigger Python test setup scripts?

Cypress can call a local task or a small test API route before a test. That route runs the Python code to reset rows and return fresh test credentials.

Can both tools run at the same time against one database?

Yes, if you isolate their data with unique user records or separate database schemas. Never let parallel workers overwrite the same rows at the same time.

The query runs. The emails stay hidden.