Fix issues caused by pytest.mark.parametrize

This commit is contained in:
Michael Mintz 2023-03-04 20:37:00 -05:00
parent 933bae904a
commit 018b3be69f
2 changed files with 18 additions and 15 deletions

View File

@ -395,7 +395,11 @@ def get_test_id(test):
def get_test_name(test):
if "PYTEST_CURRENT_TEST" in os.environ:
test_name = os.environ["PYTEST_CURRENT_TEST"].split(" ")[0]
full_name = os.environ["PYTEST_CURRENT_TEST"]
if "] " in full_name:
test_name = full_name.split("] ")[0] + "]"
else:
test_name = full_name.split(" ")[0]
elif test.is_pytest:
test_name = "%s.py::%s::%s" % (
test.__class__.__module__.split(".")[-1],
@ -410,16 +414,6 @@ def get_test_name(test):
)
if test._sb_test_identifier and len(str(test._sb_test_identifier)) > 6:
test_name = test._sb_test_identifier
if hasattr(test, "_using_sb_fixture_class"):
if test_name.count(".") >= 2:
parts = test_name.split(".")
full = parts[-3] + ".py::" + parts[-2] + "::" + parts[-1]
test_name = full
elif hasattr(test, "_using_sb_fixture_no_class"):
if test_name.count(".") >= 1:
parts = test_name.split(".")
full = parts[-2] + ".py::" + parts[-1]
test_name = full
return test_name

View File

@ -14048,17 +14048,21 @@ class BaseCase(unittest.TestCase):
if self._sb_test_identifier and len(str(self._sb_test_identifier)) > 6:
test_id = self._sb_test_identifier
test_id = test_id.replace(".py::", ".").replace("::", ".")
test_id = test_id.replace("/", ".")
test_id = test_id.replace("/", ".").replace(" ", "_")
elif hasattr(self, "_using_sb_fixture") and self._using_sb_fixture:
test_id = sb_config._latest_display_id
test_id = test_id.replace(".py::", ".").replace("::", ".")
test_id = test_id.replace("/", ".")
test_id = test_id.replace("/", ".").replace(" ", "_")
return test_id
def __get_test_id_2(self):
"""The id for SeleniumBase Dashboard entries."""
if "PYTEST_CURRENT_TEST" in os.environ:
return os.environ["PYTEST_CURRENT_TEST"].split(" ")[0]
full_name = os.environ["PYTEST_CURRENT_TEST"]
if "] " in full_name:
return full_name.split("] ")[0] + "]"
else:
return full_name.split(" ")[0]
if hasattr(self, "is_behave") and self.is_behave:
return self.__get_test_id()
test_id = "%s.%s.%s" % (
@ -14075,7 +14079,11 @@ class BaseCase(unittest.TestCase):
def __get_display_id(self):
"""The id for running a test from pytest. (Displayed on Dashboard)"""
if "PYTEST_CURRENT_TEST" in os.environ:
return os.environ["PYTEST_CURRENT_TEST"].split(" ")[0]
full_name = os.environ["PYTEST_CURRENT_TEST"]
if "] " in full_name:
return full_name.split("] ")[0] + "]"
else:
return full_name.split(" ")[0]
if hasattr(self, "is_behave") and self.is_behave:
file_name = sb_config.behave_scenario.filename
line_num = sb_config.behave_line_num
@ -14222,6 +14230,7 @@ class BaseCase(unittest.TestCase):
alt_test_id = sb_config._display_id[test_id]
alt_test_id = alt_test_id.replace(".py::", ".")
alt_test_id = alt_test_id.replace("::", ".")
alt_test_id = alt_test_id.replace(" ", "_")
if alt_test_id in sb_config._results.keys():
sb_config._results.pop(alt_test_id)
if test_id in sb_config._results.keys() and (