File: decorators.rst

package info (click to toggle)
python-polyfactory 2.22.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,892 kB
  • sloc: python: 11,338; makefile: 103; sh: 37
file content (12 lines) | stat: -rw-r--r-- 633 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
The ``post_generated`` decorator
--------------------------------

The :class:`post_generated <polyfactory.decorators.post_generated>` decorator wraps a ``classmethod`` into a
:class:`PostGenerated <polyfactory.fields.PostGenerated>` field. This is useful when the post generated field depends
on the current factory, usually its ``__faker__`` and/or ``__random__`` attribute. For example:

.. literalinclude:: /examples/decorators/test_example_1.py
    :caption: Using the ``post_generated`` decorator
    :language: python

All classmethod parameters after ``cls`` must be named as the fields this post generated field depends on.