Marshmallow: Wiping class_registry for unit testing

Created on 6 Apr 2020  路  2Comments  路  Source: marshmallow-code/marshmallow

I'm doing a number of unit tests in a row, and between each one, the class_registry object maintains. This is as intended when the app is running, but not so when just running unit tests.

Is there a best practice for wiping the class_registry? Or for just removing all registered objects since the class was created?

question

Most helpful comment

.. warning::

    This module is treated as private API.
    Users should not need to use this module directly.

https://marshmallow.readthedocs.io/en/stable/api_reference.html#module-marshmallow.class_registry

It doesn't look like this use case has been considered before. Is there a specific side effect this is causing in your tests?

This code hasn't changed in the last 6 years, so it's probably safe to just marshmallow.class_registry._registry.clear() in your tests.

All 2 comments

.. warning::

    This module is treated as private API.
    Users should not need to use this module directly.

https://marshmallow.readthedocs.io/en/stable/api_reference.html#module-marshmallow.class_registry

It doesn't look like this use case has been considered before. Is there a specific side effect this is causing in your tests?

This code hasn't changed in the last 6 years, so it's probably safe to just marshmallow.class_registry._registry.clear() in your tests.

I agree with @deckar01 's suggestion. The warning in the docs is moreso to avoid us from having to consider API changes to class_registry a breaking change, but the reality is that module really shouldn't change very often.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

symonk picture symonk  路  3Comments

manoadamro picture manoadamro  路  3Comments

tadams42 picture tadams42  路  3Comments

Ovyerus picture Ovyerus  路  3Comments

lassandroan picture lassandroan  路  3Comments