unittest.mock — mock object library — Python 3.14.7 documentation

docs.python.org

Tin mới

unittest — Unit testing framework

unittest.mock — getting started

Python Module Index

3.14.7 Documentation

The Python Standard Library

object.__getattr__

If an AttributeError is raised by PropertyMock, it will be interpreted as a missing descriptor and __getattr__() will be called on the parent mock:

Deleting Attributes¶

Mock objects create attributes on demand. This allows them to pretend to be objects of any type.

Deleting Attributes¶

Mock objects create attributes on demand. This allows them to pretend to be objects of any type.

container.__iter__

Patch a dictionary, or dictionary like object, and restore the dictionary to its original state after the test, where the restored dictionary is a copy of the dictionary as it was before the test.

Mocking Magic Methods¶

Mock supports mocking the Python protocol methods, also known as “magic methods”. This allows mock objects to replace containers or other objects that implement Python protocols.

Mocking Magic Methods¶

Mock supports mocking the Python protocol methods, also known as “magic methods”. This allows mock objects to replace containers or other objects that implement Python protocols.

os.PathLike.__fspath__()

Changed in version 3.8: Added support for os.PathLike.__fspath__().

copy: Shallow and deep copy operations.

Changed in version 3.7: The sentinel attributes now preserve their identity when they are copied or pickled.

pickle: Convert Python objects to streams of bytes and back.

Changed in version 3.7: The sentinel attributes now preserve their identity when they are copied or pickled.

io.IOBase.readline

A helper function to create a mock to replace the use of open(). It works for open() called directly or used as a context manager.