@@ -736,9 +736,11 @@ class example(object):
736736 :param bool user_help: whether this example should be included in
737737 user-facing help output such as `.help command`
738738 (optional; default ``False``; see below)
739- :param bool online: if ``True``, |pytest|_ will mark this
740- example as "online" (optional; default ``False``; see
741- below)
739+ :param bool online: if ``True``, |pytest|_ will mark this example as
740+ "online" (optional; default ``False``; see below)
741+ :param bool vcr: if ``True``, this example's HTTP requests & responses will
742+ be recorded for later reuse (optional; default ``False``;
743+ see below)
742744
743745 .. |pytest| replace:: ``pytest``
744746 .. _pytest: https://pypi.org/project/pytest/
@@ -766,13 +768,21 @@ class example(object):
766768 can override this choice or include multiple examples by passing
767769 ``user_help=True`` to one or more ``example`` decorator(s).
768770
769- Finally, passing ``online=True`` makes that particular example skippable if
770- Sopel's test suite is run in offline mode, which is mostly useful to make
771- life easier for other developers working on Sopel without Internet access.
771+ Passing ``online=True`` makes that particular example skippable if Sopel's
772+ test suite is run in offline mode, which is mostly useful to make life
773+ easier for other developers working on Sopel without Internet access.
774+
775+ Finally, ``vcr=True`` records the example's HTTP requests and responses for
776+ replaying during later test runs. It can be an alternative (or complement)
777+ to ``online``, and is especially useful for testing plugin code that calls
778+ on inconsistent or flaky remote APIs. The recorded "cassettes" of responses
779+ can be committed alongside the code for use by CI services, etc. (See
780+ `VCR.py <https://github.com/kevin1024/vcrpy>`_ & `pytest-vcr
781+ <https://github.com/ktosiek/pytest-vcr>`_)
772782 """
773783 def __init__ (self , msg , result = None , privmsg = False , admin = False ,
774784 owner = False , repeat = 1 , re = False , ignore = None ,
775- user_help = False , online = False ):
785+ user_help = False , online = False , vcr = False ):
776786 # Wrap result into a list for get_example_test
777787 if isinstance (result , list ):
778788 self .result = result
@@ -787,6 +797,7 @@ def __init__(self, msg, result=None, privmsg=False, admin=False,
787797 self .owner = owner
788798 self .repeat = repeat
789799 self .online = online
800+ self .vcr = vcr
790801
791802 if isinstance (ignore , list ):
792803 self .ignore = ignore
@@ -820,6 +831,9 @@ def __call__(self, func):
820831 if self .online :
821832 test = pytest .mark .online (test )
822833
834+ if self .vcr :
835+ test = pytest .mark .vcr (test )
836+
823837 sopel .test_tools .insert_into_module (
824838 test , func .__module__ , func .__name__ , 'test_example'
825839 )
0 commit comments