Think Build Implement Repeat
London, UK +44 7367 067226
WhatsApp FOLLOW f in X
  1. Home
  2. Blog
  3. Confidence in Code That Runs Unattended
Python & Django

Confidence in Code That Runs Unattended

Testing Python services that run unattended: transformations, boundaries and failure paths, real data shapes, and mocking the boundary, not the logic.

Updated 2 min readBy SpiderHunts Technologies

Free estimateNo obligation

Get a free estimate

Tell us what you need. A senior engineer reads every enquiry.

Takes under a minute. We never share your details.

  • Free consultation
  • No commitment
  • NDA on request

Prefer to talk? Book a free 30-minute call →

Quick answer — TL;DR

Test the transformations, the boundaries and the failure paths. Services that run unattended need their error handling tested more than their happy path.

Unattended code needs different testing

A web application has users who report problems. A service running overnight has nobody watching, which means its failure handling matters more than its normal operation.

The question is not whether it works with good input. It is what happens with the record that has a null where a date should be, at three in the morning.

What to test

  1. Transformations — the logic that turns input into output
  2. Boundaries — what happens with empty, huge, malformed input
  3. Failure paths — external service down, timeout, bad response
  4. Idempotency — running the same thing twice
  5. Reconciliation — the counts add up

Test against real data shapes

  • Use anonymised production samples, including the awkward ones
  • Include the record that broke it last time
  • Test with an empty input set
  • Test with a volume larger than you expect
  • Test with a deliberately corrupted input

Synthetic clean test data tests the code you wrote against the assumptions you made, which is the least useful thing to verify.

Mock the boundary, not the logic

MockDo not mock
External API callsYour own transformations
Time, where behaviour depends on itDatabase queries in integration tests
RandomnessThe logic under test
Slow third-party servicesAnything you actually want verified

Run them automatically

Tests that require someone to remember stop being run. They should execute on every push, with a visible result, blocking a merge on failure.

That is a day of setup and it is what turns a test suite into a working safety net rather than a good intention.

FAQ

Frequently asked questions

The questions readers ask us after this guide.

Still have a question?

Ask us directly — a senior engineer will get back to you.

Ask about your project

How much coverage is enough?

Enough to change the code confidently. That is usually the transformations and the failure paths, not every line.

Should tests hit a real database?

For integration tests, yes — a test database. Mocking the database tests your mocks.

How do we test external integrations?

Contract tests against recorded responses, plus a periodic check against the real service to detect changes.

What about testing machine learning code?

Test the data handling and the feature computation. Model quality is evaluated statistically, which is a different exercise.

Keep reading

More on Python & Django

Python & Django

An API Other Systems Can Depend On

Designing a Python API service others can depend on: validation at the boundary, consistent errors and status codes, early versioning and documentation.

Python & Django

Moving and Transforming Data Reliably

Building data pipelines in Python that cope with malformed input: restartable stages, quarantining failures, reconciling counts and alerting on absence.

Start here

Service that runs overnight and sometimes does not?

Its failure paths are probably untested. That is where the tests are worth writing.

  1. You tell us what you needTwo minutes on the form, or a message on WhatsApp.
  2. A senior engineer reviews itAnd comes back with questions, a realistic range and an honest view on fit.
  3. Free 30-minute scoping callWe talk through scope, options and a realistic estimate — with no obligation.
Free estimateNo obligation

Talk to someone who builds this

Send a short brief and we will come back with an honest view and a realistic range.

Takes under a minute. We never share your details.

  • Free consultation
  • No commitment
  • NDA on request

Prefer to talk? Book a free 30-minute call →