Experimental

There are some features that I find neat and helpful but there is no consensus on how readable they are.

attr

A wrapper to use a fixture as a container attribute.

patcher

A fixture to patch and delete attributes of the given object.

class pytypest.experimental.attr(fixture: Fixture[P, R], *args: P.args, **kwargs: P.kwargs)

A wrapper to use a fixture as a container attribute.

A fixture wrapped with attr can be accessed as a class attribute without explicitly calling it. It’s equivalent to defining a @property that calls the fixture inside and returns its result but shorter.

class Fixtures:
    user = attr(get_user)

def test_user():
    f = Fixtures()
    assert f.user.name == 'mark'
pytypest.experimental.patcher(target: object | str) Iterator[Any]

A fixture to patch and delete attributes of the given object.

Patch an attribute:

patcher(logging).info = Mock()

Delete an attribute:

del patcher(logging).info

The object can be also specified as a full import path string:

patcher('logging').info = Mock()

All changes to the object will be reverted when leaving the context.