simplistix / sybil

Automated testing for the examples in your documentation.
https://sybil.readthedocs.io/en/latest/
Other
74 stars 14 forks source link

Skip comments do not skip next pieces of code #39

Closed mgiammar closed 2 years ago

mgiammar commented 2 years ago

I recently found Sybil as a way to test my static documentation code with pytest. On some of the documentation pages, Matplotlib plt.show() is invoked, and running pytest makes plots appear when each code block is executed.

I added .. skip: next before the code blocks as shown below

Some documentation

.. skip: next

.. code-block:: python

    import matplotlib.pyplot as plt
    plt.plot([1, 2, 4, 9])
    plt.show()

Commentary about above figure

However, plots are still opened when running pytest. Further, I tried the following code

.. skip: next

>>> print("Foo Bar")

which still throws the error

Expected nothing
Got:
    Foo Bar

when running pytest.

Any ideas on why skip might be failing? Or am I using skip incorrectly?

cjw296 commented 2 years ago

What's the contents of your conftest.py?

mgiammar commented 2 years ago

# -*- coding: utf-8 -*-
from pprint import pprint
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pytest

# LIBRARY IMPORTS
from mrsimulator import Coupling
from mrsimulator import signal_processing as sp
from mrsimulator import Simulator
from mrsimulator import Site
from mrsimulator import SpinSystem
from mrsimulator.methods import BlochDecayCTSpectrum
from mrsimulator.methods import Method2D
from mrsimulator.models import CzjzekDistribution
from mrsimulator.models import ExtCzjzekDistribution
from mrsimulator.spin_system.isotope import Isotope
from mrsimulator.spin_system.tensors import SymmetricTensor
from mrsimulator.transition import Transition
from mrsimulator.transition import TransitionPathway

from sybil import Sybil
from sybil.parsers.codeblock import PythonCodeBlockParser
from sybil.parsers.doctest import DocTestParser
from sybil.parsers.skip import Skip
from plot_directive_parser import PythonPlotParser

font = {"weight": "light", "size": 9}
matplotlib.rc("font", **font)

@pytest.fixture(autouse=True)
def test_models(doctest_namespace):
    cz_model = CzjzekDistribution(0.5)
    doctest_namespace["cz_model"] = cz_model

    S0 = {"Cq": 1e6, "eta": 0.3}
    ext_cz_model = ExtCzjzekDistribution(S0, eps=0.35)
    doctest_namespace["ext_cz_model"] = ext_cz_model

@pytest.fixture(autouse=True)
def add_site(doctest_namespace):
    # long pytest fixture; code removed for brevity
    pass

pytest_collect_file = Sybil(
    parsers=[
        PythonCodeBlockParser(),
        DocTestParser(),
    ],
    pattern="*.rst",
    fixtures=["add_site", "test_models"]
).pytest()
cjw296 commented 2 years ago

Looks like you haven't included the skip parser in your config, here's an example: https://github.com/simplistix/sybil/blob/master/conftest.py#L13