Frequently asked questions

Why don’t my decorated functions get traces?

If you have decorators that don’t use functools.wraps on the wrapper function returned by the decorator, MonkeyType won’t be able to trace functions decorated with them. MonkeyType needs the __wrapped__ attribute added by functools.wraps to be able to trace the frame back to an importable function.

I’m using Django 1.11+ and monkeytype run test generates no traces.

Django 1.11 enabled parallel test runs by default. This means your tests run in separate subprocesses; MonkeyType is tracing only the main supervisor process, which runs only Django code (that is excluded from tracing by the default code filter). To get traces, use --parallel 1 when running your tests under MonkeyType tracing.

I’m using Django, and I get an AppRegistryNotReady exception when I run monkeytype.

You need to use the cli_context() config method to call django.setup().

I run tests against my package installed in site-packages, and I get no traces.

The default code_filter() excludes all code from the standard library and site-packages, on the assumption that it is third-party code that isn’t useful to trace. If you want to trace calls to a package in site-packages, you can set the environment variable MONKEYTYPE_TRACE_MODULES to a comma-separated list of package/module names you want to trace; only these modules will be traced, wherever they are installed. For more advanced behaviors, you can define your own custom code filter.

Why did my test coverage measurement stop working?

MonkeyType uses the same sys.setprofile hook that uses to measure Python code coverage, so you can’t use MonkeyType and coverage measurement together. If you want to run your tests under MonkeyType tracing, disable coverage measurement for that run, and vice versa.

MonkeyType stopped generating TypedDicts.

Since 19.11.2 TypedDict generation is disabled by default. To enable it, create a config file with the following content:

from monkeytype.config import DefaultConfig

class MyConfig(DefaultConfig):
    def max_typed_dict_size(self) -> int:
        The maximum size of string-keyed dictionary for which per-key value types
        will be stored, and (if the traced keys and value types are consistent),
        a TypedDict will be emitted instead of Dict.
        Return 0 to disable per-key type tracking and TypedDict generation.
        return 10

CONFIG = MyConfig()