From 6ea6f0dac80b9188536131201098f2c12a9b9987 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 23 Jul 2020 17:33:17 +0300 Subject: [PATCH] junitxml: compile a regex lazily Instead of slowing down startup, and making the code harder to follow, compile it lazily (it is still cached internally). --- src/_pytest/junitxml.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/_pytest/junitxml.py b/src/_pytest/junitxml.py index 8c68d196a..6f0d90330 100644 --- a/src/_pytest/junitxml.py +++ b/src/_pytest/junitxml.py @@ -68,8 +68,6 @@ del _legal_chars del _legal_ranges del _legal_xml_re -_py_ext_re = re.compile(r"\.py$") - def bin_xml_escape(arg: object) -> py.xml.raw: def repl(matchobj: Match[str]) -> str: @@ -473,7 +471,7 @@ def mangle_test_address(address: str) -> List[str]: pass # convert file path to dotted path names[0] = names[0].replace(nodes.SEP, ".") - names[0] = _py_ext_re.sub("", names[0]) + names[0] = re.sub(r"\.py$", "", names[0]) # put any params back names[-1] += possible_open_bracket + params return names