Skip to content
Advertisement

Get type object defined inside doctest by type name

I am trying to doc-test a method that accepts a module object module and a string with the name of the type type_name inside that module :

JavaScript

When I am trying to get the type object with getattr (in reality, the method does more than just that), I am getting the error:

JavaScript

Is it possible to doc-test this method without having to define the A class outside of the doc-test?

Advertisement

Answer

For some reason the defined A class is not present in the __dict__. Maybe this is a problem with the doctest itself. As a work around you can add it like this:

sys.modules[A.__module__].A = A

or

sys.modules[A.__module__].__dict__['A'] = A

JavaScript

This is how I am calling the test:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement