Skip to main content

simple_test_generator

Automated, comprehensive and clean pytest test cases.

Description

If we format our code with tools like Black, then why don't we do the same with our tests?

Helps you reach 100% test coverage with real-world test cases. Tests that are generated "just work", i.e they are clean, unaware of implementation details, and doesn't require active maintenance.

It works well if your functions are deterministic (e.g pure).

If not, then you should probably make them so!

It's DDT for pytest (development-driven testing, data-driven tests, or both 🤓)

why?

Too tedious/hard to generate custom data for your application?

  • save time by having tests generated for you 🎉
  • dramatically increase test code coverage with little effort
  • write more maintainable tests by separating code and data
  • helps you organise your test code consistently in new projects, or:
  • replace your existing disorganised test code 👍
  • accelerate your migration to pytest

Tests that you write manually can still be made to follow the same conventions as simple_test_generator for consistency

Using in normal runs

Using while running tests

then, confirm that your test cases expected value are correct.

finally, install it only as a test dependency.

Demos

See botostubs going from 0 to 99% under 20 seconds!

Releasing on PyPI

  • pipenv shell
  • flit build
  • flit publish

Enter password when prompted.

Docs

Running over and over write test cases in new files to avoid overwriting your previous test cases. The filenames are appended with -00, -01, ... for up to 10 files.

If your function arguments are not serialisable, then test cases won't be generated. You will see an error in the logs for that function.

Dev docs

section still rough; personal notes

calling -m simple_test_generator isn't dropping in debugger. It works when using as a library with Recorder(): ...

Notes

  • It won't be able to support all types of data, e.g asserting functions that return other functions. See section on how to handle this.
  • This project uses pickling to load the test data. If you're the one generated test data, then it should be fine loading it during tests. Otherwise, don't load untrusted test data.

Features

  • Handles functions that return generators by automatically extending these into Python lists so that they can be asserted.

TODO

  • Minor issue: functions in your main module may be loaded twice, creating identical test cases twice for that function. (maybe happening only in this project)
  • Support functions that return functions. We need a reliable way to assert equivalence between a function and its deserialised representation.

These projects resemble this one but mine requires much less effort on your part and generates even less boilerplate 😊

What if you have test failures?

It may be due to a bug in simple_test_generator but it's probably because it's difficult to serialise all data types, e.g file descriptors.

Cases that you should handle on your own:

  • Assertion does not work properly on your objects

You should define an __eq__ function in your class. This will ensure that pytest asserts the return values properly.

How to report in issue

  1. Raise an issue here about the test failure (or upvote an existing one)
  2. Paste your function code (or its signature)
  3. Paste the json file that simple_test_generator generated, e.g test-data/path/to/function/01.json
  4. State what you were expecting
  5. State what happened instead

Copyright

Released under the MIT licence. See file named LICENCE for details.

Metadata

Release files for simple_test_generator 0.27

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simple_test_generator 0.27
File Size Uploaded Provenance
simple_test_generator-0.27.tar.gz 50.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for simple_test_generator 0.27
File Interpreter ABI Platform
simple_test_generator-0.27-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 63.5 kB

Release files / simple_test_generator-0.27.tar.gz

Download URL simple_test_generator-0.27.tar.gz
Size 50.7 kB
Tags Source
SHA-256 checksum
How to use checksums
50d0cdf29202659a93a0613825beb95b979bf958259572ad91ebc3f91db6298b
BLAKE2b-256 checksum
How to use checksums
2b922386ed23bc99ac56fa250968da8eb5930c0d3a8f5112531589b07d556a1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.22.0

Release files / simple_test_generator-0.27-py2.py3-none-any.whl

Download URL simple_test_generator-0.27-py2.py3-none-any.whl
Size 12.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
0ae0257ba10c039adf484eedf26a80870e74277af3c9c5d4aaacbe2ec1c8ba44
BLAKE2b-256 checksum
How to use checksums
0db26ff160ceb23664792acb93ae2660ce89f6b9f29e7e743d2477aa071a4fe6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.22.0

Security for simple_test_generator 0.27

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page