The Simplest Way to Make Buildkite and Pytest Work Like They Should
Using buildkite and pytest together lets teams run fast Python tests on their own servers. Buildkite schedules the jobs in the cloud, while pytest runs the test suite on your local agents. This setup keeps your source code and test databases inside your private network. You get a clean cloud dashboard without opening your firewall to outside test runners. Your team can trigger test suites on every code push and get fast feedback. How permissions and data flow between buildkite and pytest The
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.
Using buildkite and pytest together lets teams run fast Python tests on their own servers. Buildkite schedules the jobs in the cloud, while pytest runs the test suite on your local agents.
This setup keeps your source code and test databases inside your private network. You get a clean cloud dashboard without opening your firewall to outside test runners. Your team can trigger test suites on every code push and get fast feedback.
How permissions and data flow between buildkite and pytest
The workflow starts when a developer pushes new code to a source repo. Buildkite detects the change and places a new job into your build queue. A local agent sitting inside your network polls the queue and claims the job.
That agent pulls the code and starts a fresh container for the test run. Next, the agent triggers pytest to discover and execute the Python test files. Pytest often needs to log in to test databases or external services during a run.
The agent passes identity tokens or database keys into the test runtime. Pytest uses those keys to read and write test records in your staging backend. When the test suite finishes, pytest writes a summary file to the agent disk.
The agent uploads the test results and logs back to the cloud dashboard. Developers can then check which tests failed and read the error output right away. Data flows out to the dashboard, while private keys stay inside your local network.
Common failure modes and how to scope runner roles
Many teams make the mistake of putting long-lived keys directly on build agents. If every job shares the same static key, any branch can read all test databases. A bad script in a pull request could wipe out shared staging tables.
Shared service accounts also make it hard to track which job ran a bad query. When five test suites run at once, database logs show only one shared user name. Teams waste hours trying to match failed pytest runs to slow database queries.
Broad network paths create another major risk for your build farm. Build agents often sit in a flat network subnet with open access to internal services. If a test package includes bad code, it can reach production servers from the runner.
End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
You can fix this by giving each build queue a tight network role. Split your agents into separate groups for unit tests and database tests. Unit test agents should have no network path to internal databases at all.
For integration tests, assign a narrow database role that can only touch test schemas. Make sure your test runner creates a fresh schema for each build and drops it later. Keep sensitive fields like emails and phone numbers out of your test seed files.
Speeding up test runs across parallel agents
Large Python apps can take hours to test on a single machine. Buildkite lets you split a single job across dozens of parallel agents at once. Each agent pulls the same code but runs only a small slice of the suite.
For this to work, pytest must know which files to run on each node. You can pass the agent index number into the test runner at startup. Pytest then divides the test list and runs only its assigned group of files.
Parallel runs put heavy load on your shared test backends and cloud roles. Fifty agents starting at the same second can max out your database connection limits. You should set clear connection caps on each test worker to avoid crashes.
Use local containers for cache services so parallel agents do not fight over shared state. When each agent runs its own isolated backend, tests finish fast and stay reliable.
Add runtime guardrails and masking beside your databases and APIs
Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.
Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.
Frequently asked questions
How do we keep test runners from touching production databases?
Place your build agents in an isolated network subnet with strict firewall rules. Give the agent identity role permissions to reach only staging and test database instances.
How should pytest handle database state during parallel runs?
Have each test worker create a unique database schema named after the build job ID. Drop the schema when the test finishes so workers never overwrite each other.
Where should we store test logs and failure reports?
Configure pytest to write test reports to a local folder on the build agent. Set the agent to upload those files as build artifacts before cleaning up the disk.
Related guides
In this post