There is a module like this:
"""I am a module.
Examples
--------
>>> import yaml # optional dependency
>>> do_stuff
"""
__doctest_requires__ = {'*': ['yaml']}
# Real code to follow
In a CircleCI job with pytest-xdist installed and parallel run is enabled, the doctest fails with ImportError: import yaml failed but the other jobs passed.
xref astropy/astropy#10257