Hello,
Is there a way to run some code before the doctests of a file are performed?
Consider the following simple example of a module "mymodule" where is
defined a class "A".
mymodule.py:
---
class A():
def method1(self):
"""
Return 123.
TESTS::
sage: from mymodule import A
sage: a = A()
sage: a.method1()
123
"""
return 123
def method2(self):
"""
Return 456.
TESTS::
sage: from mymodule import A
sage: a = A()
sage: a.method2()
456
"""
return 456
It seems that I have to import "A" in the doctest of each method,
otherwise I get an error that it is not defined.
Is there a way to import "A" (and even to define "a") only once for all
the doctests of the file?
By doing some research online about doctests before writing this message
I learned about the existence of the "extraglobs" parameter but I do not
see how I could use it here ( 2nd answer of
https://stackoverflow.com/questions/2708178/python-using-doctests-for-classes
).
Any idea?
If this matters, the module I am working on is of the form of a
pip-installable package prepared following the example at
https://github.com/sagemath/sage_sample .
Best regards,
Jean-Florent.