Skip to main content

Why does Deflector exist?

💡 Deflector is a minimalist testing library for Python designed to simplify test writing with a clear and intuitive syntax, allowing developers to create and run tests quickly and efficiently without unnecessary complications.

check High isolation level per file
check Performant and lightweight
check Fully typed library


Quickstart

check Install

$ pip install deflector

Or with poetry

poetry add deflector -G dev

check Test

tests/test_file1.py
from deflector import affirm


affirm.equal(1, 1, "My first test with deflector")

check Run

deflector # or poetry run deflector

Or defining the directory where the tests are:

deflector --dir tests

Features

check Main

Function Description
affirm 🔍 Test assertion.
it 🤹🏻‍♀️ Isolate tests.
describe 🤹🏻‍♀️ Grouping tests.
before_each • after_each 🃏 Functions for test setup and teardown.

Affirm

The affirm is used to create tests that validate whether the behavior of your code is as expected, checking the correspondence between values ​​and triggering errors if there are discrepancies.

from deflector import affirm
Function Description
ok Checks if a value is truthy.
equal Compares if two values are equal.
not_equal Verifies if two values are different.
match_re Checks if a string matches a regex.
does_not_match_re Verifies if a string does not match a regex.
Ok
affirm.ok(value, message)
affirm.ok(True, "Ok")
Equals
affirm.equal(value, expected, message)
affirm.equal(1 + 2, 3, "Equal: Sum 1+2=3")
Not Equals
affirm.not_equal(value, expected, message)
affirm.not_equal(1 + 2, 4, "Not Equal: Sum 1+2!=4")
Match Regex
affirm.match_re(value, reg_exp, message)
affirm.match_re("acab", "ab", "Match Regex: ab in acab")
Does Not Match Regex
affirm.does_not_match_re(value, reg_exp, message)
affirm.does_not_match_re("ab", "abc", "Does Not Match Regex: ab not in a")

It

from deflector import affirm, it

@it("It Test 1")
def test_1() -> None:
    affirm.ok(True, "Ok")
    affirm.equal(1 + 1, 2, "Equal")
    affirm.not_equal(1 + 2, 1, "Not Equal")
    affirm.match_re("acab", "ab", "Match Re")
    affirm.does_not_match_re("a", "ab", "Does Not Match Re")

Describe

from deflector import affirm, describe, it

@describe("Main 1")
def describe_main() -> None:
    @it("It Test 1")
    def test1() -> None:
        affirm.equal(1 + 1, 2, "Equal 1+1=2")

    @it("It Test 2")
    def test2() -> None:
        affirm.match_re("acab", "ab", "Match Re")

Before Each • After Each

from deflector import affirm, describe, it

@describe("Main 1")
def describe_main() -> None:
    x = 1

    @before_each()
    async def start() -> bool:
        nonlocal x
        await asyncio.sleep(1)
        x += 1
        return True

    @after_each()
    async def end_() -> bool:
        nonlocal x
        await asyncio.sleep(1)
        x = 1
        return True

    @it("It Test 1")
    def test1() -> None:
        affirm.equal(x, 2, "Equal Before Each")
        affirm.equal(1 + 1, 2, "Equal 1")
        affirm.equal(1 + 1, 2, "Equal 2")

    @it("It Test 2")
    def test2() -> None:
        affirm.equal(x, 2, "Equal After Each")
        affirm.equal(1 + 1, 2, "Equal")
        affirm.not_equal(1 + 1, 1, "Not Equal")
        affirm.ok(True, "Ok")
        affirm.match_re("acab", "ab", "Match Re")
        affirm.does_not_match_re("a", "ab", "Does Not Match Re")

Metadata

Release files for deflector 0.1.1

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

Source distribution (sdist)

Source distribution for deflector 0.1.1
File Size Uploaded
deflector-0.1.1.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for deflector 0.1.1
File Interpreter ABI Platform
deflector-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 21.2 kB

Release files / deflector-0.1.1.tar.gz

Download URL deflector-0.1.1.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9f977f1e547c8a54fd29b8d0e8fac47413a532f37155319023fdeebb1e12a56f
BLAKE2b-256 checksum
How to use checksums
8eec327cbaeb219e47519d176076dc5d6f00cfb3ac8802e40d944f43421e1cb8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-41-generic

Release files / deflector-0.1.1-py3-none-any.whl

Download URL deflector-0.1.1-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f88577e2f52841ef32386ce9737f7342c0b7c0cbad8bafebfd183f6e39ba1419
BLAKE2b-256 checksum
How to use checksums
e04c44e9f5869caf443967c2cf0e2c7c9b97e280aad9c0c40c9676665fabaee0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-41-generic

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

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