Hi all,

I'm trying to make it possible to use pytest with SymPy. I'm mostly
there for the main tests now and the next step is to try and get it
working for the doctests. Currently SymPy has it's own test runner
which runs the doctests but it works a little differently from the
standard doctests.

Firstly SymPy's doctests are required to import all names use in the
doctest. Standard doctest allows names from the enclosing module to be
used without imports. It's considered important in SymPy that the
doctests should error out if the imports are not included.

So for example if I have

def f():
    ''''
    >>> f()
    42
    '''
    return 42

then this should give an error in the doctests because the function f
is undefined. A valid doctest for this would look like
def f():
    ''''
    >>> from module import f
    >>> f()
    42
    '''
    return 42

It seems there is a feature in sympy to inject symbols into the
doctest namespace:
https://docs.pytest.org/en/latest/doctest.html#the-doctest-namespace-fixture
but I'm really interested in removing things from the namespace to
test for errors when something isn't properly imported in the doctest.

The other issue is that SymPy has a few different ways of displaying
output at the terminal: the repr, the ascii version, and the pretty
version. The doctests are written for the ascii version but under
pytest the pretty version is found as output. You can see this problem
if you run e.g.

$ git clone https://github.com/sympy/sympy.git
$ cd sympy
$ pytest --doctest-modules sympy/solvers/ode.py

An example of the failures is

/Users/enojb/current/sympy/sympy/sympy/solvers/ode.py:1501: DocTestFailure
___________________ [doctest] sympy.solvers.ode.constant_renumber
2896     Only constants in the given range (inclusive) are renumbered;
2897     the renumbering always starts from 1:
2898
2899     >>> constant_renumber(C1 + C3 + C4, 'C', 1, 3)
2900     C1 + C2 + C4
2901     >>> constant_renumber(C0 + C1 + C3 + C4, 'C', 2, 4)
2902     C0 + 2*C1 + C2
2903     >>> constant_renumber(C0 + 2*C1 + C2, 'C', 0, 1)
2904     C1 + 3*C2
2905     >>> pprint(C2 + C1*x + C3*x**2)
Expected:
                    2
    C1*x + C2 + C3*x
Got:
                    2
    C₁⋅x + C₂ + C₃⋅x

To make this work I need to figure out a way for pytest to meet these
two requirements:
1) Customise namespace used for tests
2) Customise the function that generates output before comparing with
expected output of a doctest.

Does anyone know if it's possible to do either of these things with pytest?

--
Oscar
_______________________________________________
pytest-dev mailing list
pytest-dev@python.org
https://mail.python.org/mailman/listinfo/pytest-dev

Reply via email to