Skip to main content

Fluent API for assertions supporting pytest with focus on developer experience.

Project description

fluent-assertions for Pytest

This project aims to provide a fluent API for assertions supporting pytest, designed with simplicity and ease of use in mind.

The core idea is to make writing assertions more intuitive, readable, and enjoyable by offering a fluent interface that leverages the power of modern Python typing. It aims to be easy to use in any IDE for enhanced developer productivity.

⚠️ Current Status This project is in its early exploratory phase. While the core functionality is present, it is not yet fully mature. Use with caution as the API may evolve rapidly and changes could be breaking.

🎯 Features

  • Fluent API for pytest assertions.
  • Full typing support for IDE-friendly development.
  • Designed to improve readability and expressiveness of test cases.

🛠️ Examples

Classes:

from fluent_assertions import assert_that

def test_class(): 
    @dataclasses.dataclass
    class User:
        name: str
        age: int
    
    def get_name(self):
        return self.name
    
    list_of_users = [User(name="Guenther", age=51), User(name="Jack", age=12)]
    (
        assert_that(list_of_users)
        .has_size(2)
        .extracting(User.get_name)
        .contains_exactly(["Guenther", "Jack"])
        .last()
        .is_equal_to("Jack")
    )

Dictionaries:

def test_dict():
    example_dict = {
        "name": "Guenther",
        "age": "51",
    }
    
    (
        assert_that(example_dict)
        .is_not_empty()
        .contains_keys(["name", "age"])
        .contains_values(["Guenther", "51"])
    )

Lists:

def test_list():
    (
        assert_that([1, 2, 3])
        .contains_only(1, 2, 3)
        .has_size(3)
        .contains_subsequence([2, 3])
    )

📦 Installation

Available on PyPi:

pip install fluent-assertions

🤝 Contributing

Feedback and collaboration are highly encouraged! If you encounter bugs, have feature requests, or want to contribute improvements, feel free to open an issue or submit a pull request.

🚧 Roadmap

  • Add more assertion types and methods.
  • Improve documentation and add examples.

📜 License

This project is licensed under the MIT License. See the LICENSE file for more details.

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

fluent_assertions-0.1.4.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

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

fluent_assertions-0.1.4-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file fluent_assertions-0.1.4.tar.gz.

File metadata

  • Download URL: fluent_assertions-0.1.4.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for fluent_assertions-0.1.4.tar.gz
Algorithm Hash digest
SHA256 fe9e895907cecd6129449391d5fe533eaf5a191cb7848b4576d5c520f1286fa1
MD5 cc5e9facc0d6d57d94bb6235d8470e19
BLAKE2b-256 0ec811cb890a804eab10c8ce6be527a104edf322075973e395f1dea469098aca

See more details on using hashes here.

File details

Details for the file fluent_assertions-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for fluent_assertions-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ba06ce58bcaa28a335c5e1c51913ab495b4001225d08f6278e9c7e8f33e3592b
MD5 706995f42396859128e721569a893212
BLAKE2b-256 77a07fb65cb8255e8619255c8ae651ef28d083d15262af8c7e0abf6557529913

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