fluent_assertions

class AssertThat(typing.Generic[~T]):

Base class for assertions of any type

AssertThat(value: ~T)
value
with_trace
def without_trace(self) -> Self:
def is_not_none(self) -> Self:
def is_none(self) -> Self:
def is_equal_to(self, value: ~T) -> Self:
class AssertThatEqualityMixin(fluent_assertions.AssertThat[~T], typing.Generic[~T]):

Mixin for equality assertions

def equals(self, value: ~T) -> None:
class AssertThatSequence(AssertThat, typing.Generic[~T]):

Assertions for sequence types

def contains(self, v: ~T) -> Self:

Verifies that the sequence contains the given value

Parameters
  • v: value to contain
Returns
def contains_only(self, *args: ~T) -> Self:

Verifies that the sequence only contains the given values, ignoring duplicates.

Parameters
  • args: values to contain
Returns
def contains_exactly(self, to_contain: Sequence[~T]) -> Self:

Verifies that the sequence contains exactly the given values (in order).

Parameters
  • to_contain: values to contain exactly
Returns
def contains_exactly_in_any_order(self, to_contain: Sequence[~T]) -> Self:

Verifies that the sequence contains exactly the given values in any order.

Parameters
  • to_contain: values to contain exactly
Returns
def contains_subsequence(self, subsequence: Sequence[~T]) -> Self:

Verifies whether the sequence contains a subsequence of the given value.

Parameters
  • subsequence: sequence to contain
Returns
def contains_only_once(self, sub_sequence: Sequence[~T]) -> Self:

Verifies that the sequence contains only once of every given values.

Parameters
  • sub_sequence: values to contain only once
Returns
def has_size(self, size: int) -> Self:

Verifies that the sequence has size

Parameters
  • size: size of the sequence to verify
Returns
def first(self) -> AssertThat[~T]:

Extracts first element of the sequence

def last(self) -> AssertThat[~T]:

Extracts last element of the sequence

def all_satisfy(self, consumer: Callable[[~T], Any]) -> Self:

Verify that all elements of the sequence are satisfying the given consumer

Parameters
  • consumer: assertions expressed via consumer
Returns
def any_satisfy(self, consumer: Callable[[~T], Any]) -> Self:

Verify that at least one element of the sequence are satisfying the given consumer

Parameters
  • consumer: assertions expressed via consumer
Returns
def none_satisfy(self, consumer: Callable[[~T], Any]) -> Self:

Verify that none of the elements of the sequence are satisfying the given consumer

Parameters
  • consumer: assertions expressed via consumer
Returns
def filtered_on( self, predicate: Callable[[~T], bool]) -> AssertThatSequence[~T]:

Filter elements based on a given predicate

Parameters
  • predicate: function that returns whether element should stay in the sequence
Returns
def extracting( self, attribute: Callable[[], ~V]) -> AssertThatSequence[~V]:

Extracting values from the given attribute of all elements in the sequence

Parameters
  • attribute: Method to extract attribute
Returns

Assertions for lists

AssertThatList(value: List[~T])

Assertions for tuples

AssertThatTuple(value: Tuple[~T, ...])

Assertions for strings

AssertThatString(value: str)
def starts_with(self, value: str) -> Self:
def ends_with(self, value: str) -> Self:
class AssertThatDict(fluent_assertions.AssertThatEqualityMixin[typing.Dict[~K, ~V]], typing.Generic[~K, ~V]):

Assertions for dictionaries

AssertThatDict(value: Dict[~K, ~V])
def contains_keys(self, keys: List[~K]) -> Self:

Verify that the dictionary contains the keys

Parameters
  • keys: list of keys to contain
Returns
def does_not_contain_keys(self, keys: List[~K]) -> Self:

Verify that the dictionary does not contain the keys

Parameters
  • keys: list of keys to contain
Returns
def contains_values(self, values: List[~V]) -> Self:

Verify that the dictionary contains the values

Parameters
  • values: list of values to contain
Returns
def is_empty(self) -> Self:

Verify that the dictionary is empty

Returns
def is_not_empty(self) -> Self:

Verify that the dictionary is not empty

Returns
def extracting(self, key: ~K) -> AssertThat[typing.Optional[~V]]:

Extracts values from the given key and returns assert that

Parameters
  • key:
Returns
def assert_that(value: Any) -> AssertThat:

Fluent api for assertions in pytest

Parameters
  • value: Value to verify
Returns