From 78eb7b331e31a37c213f46b0927915a060ed4ed0 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Tue, 12 Jul 2022 06:56:08 -0500 Subject: [PATCH] chore(_DIRECTIVE_RE): Use named grouping --- pytest_sphinx.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pytest_sphinx.py b/pytest_sphinx.py index ce81fb5..66cfe5a 100644 --- a/pytest_sphinx.py +++ b/pytest_sphinx.py @@ -70,10 +70,13 @@ def _is_doctest(config, path, parent): _OPTION_SKIPIF_RE = re.compile(r':skipif:\s*([^\n\'"]*)$') _DIRECTIVE_RE = re.compile( - r"""\s*\.\.\s - (testcode|testoutput|testsetup|testcleanup|doctest) - ::\s*([^\n'"]*)$ - """, re.VERBOSE + r""" + \s*\.\.\s + (?P(testcode|testoutput|testsetup|testcleanup|doctest)) + ::\s* + (?P([^\n'"]*)) + $ + """, re.VERBOSE | re.MULTILINE ) @@ -205,8 +208,8 @@ def add_match(directive, i, j, groups): match = _DIRECTIVE_RE.match(line) if match: - directive = getattr(SphinxDoctestDirectives, match.group(1).upper()) - groups = [x.strip() for x in (match.group(2) or "default").split(",")] + directive = getattr(SphinxDoctestDirectives, match.groupdict()["directive"].upper()) + groups = [x.strip() for x in (match.groupdict()["name"] or "default").split(",")] indentation = _get_indentation(line) # find the end of the block j = i