Skip to main content

Do testing and stuff

Project description

snektest

A Python testing framework with first-class support for async and static typing.

Installation

pip install snektest

Quick Start

Create a test file (any .py file in your project):

from snektest import test
from snektest.assertions import assert_eq

@test()
async def test_basic_math():
    result = 2 + 2
    assert_eq(result, 4)

@test()
def test_strings():
    assert_eq("hello".upper(), "HELLO")

Run your tests:

snek

Features

Async Support

Write async tests as naturally as sync ones:

@test()
async def test_async_operation():
    result = await some_async_function()
    assert_eq(result, "expected")

Parameterized Tests

Run the same test with different inputs:

from snektest import test, Param

@test(
    Param(value=1, expected=2),
    Param(value=5, expected=10),
    Param(value=0, expected=0),
)
def test_double(value: int, expected: int):
    assert_eq(value * 2, expected)

Fixtures

Set up and tear down test dependencies with function or session-scoped fixtures:

from snektest import test, session_fixture, load_fixture
from collections.abc import AsyncGenerator

@session_fixture()
async def database() -> AsyncGenerator[Database]:
    # Setup: runs once for all tests
    db = await Database.connect()
    yield db
    # Teardown: runs after all tests
    await db.close()

@test()
async def test_database_query():
    db = await load_fixture(database)
    result = await db.query("SELECT 1")
    assert_eq(result, 1)

Rich Assertions

Get helpful error messages with custom assertions:

from snektest.assertions import assert_eq, assert_true, assert_in

@test()
def test_with_assertions():
    assert_eq(actual_value, expected_value)
    assert_true(condition)
    assert_in(item, collection)

Running Tests

# Run all tests
snek

# Run specific file
snek tests/test_myfeature.py

# Run specific test
snek tests/test_myfeature.py::test_something

# Verbose output
snek -v    # INFO level
snek -vv   # DEBUG level

How It Works

snektest discovers tests by walking your project directory and finding functions decorated with @test(). Tests run concurrently by default, with a producer thread discovering tests while consumer coroutines execute them in parallel.

The fixture system uses Python generators to handle setup and teardown—code before yield runs before the test, code after yield runs after. Function fixtures are created fresh for each test, while session fixtures are shared across all tests for efficiency.

When a test fails, snektest captures rich context about what went wrong, including color-coded diffs for assertion failures and detailed tracebacks that help you quickly identify the issue.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snektest-0.2.0.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

snektest-0.2.0-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file snektest-0.2.0.tar.gz.

File metadata

  • Download URL: snektest-0.2.0.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.1

File hashes

Hashes for snektest-0.2.0.tar.gz
Algorithm Hash digest
SHA256 067ba0ab7cbd4ab9e15bf7822ca5a359b481a4e133eaaa989a757dabc4a4b620
MD5 a388bd45ab6419926b249dd4dc73af32
BLAKE2b-256 e0d5d0babde4f5fcde5409444a8cd915f1a0a74f2bb3338045bb9e7f49e78e8e

See more details on using hashes here.

File details

Details for the file snektest-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: snektest-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.1

File hashes

Hashes for snektest-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a1b1ff9af926dd9d68d026c931d38591e99d5913557ba492479f3f376d27ef80
MD5 9ebc205c36b5281eba9cb4c19c99db7d
BLAKE2b-256 04db7b7836c468db069320f36b63eb38bb05e989ec264647a892e8d2d0375651

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page