Skip to content

Commit

Permalink
Fix elapsed time unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
d-rede committed Feb 9, 2023
1 parent eec660f commit eaca553
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion tests/test_junit_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ def test_junit_xml_parser_valid_files(
@pytest.mark.parse_junit
def test_junit_xml_elapsed_milliseconds(self, freezer):
freezer.move_to("2020-05-20 01:00:00")
settings.ALLOW_ELAPSED_MS = True
env = Environment()
env.case_matcher = MatchersParser.AUTO
env.file = Path(__file__).parent / "test_data/XML/milliseconds.xml"
settings.ALLOW_ELAPSED_MS = True
file_reader = JunitParser(env)
read_junit = self.__clear_unparsable_junit_elements(file_reader.parse_file()[0])
settings.ALLOW_ELAPSED_MS = False
parsing_result_json = asdict(read_junit)
file_json = open(Path(__file__).parent / "test_data/json/milliseconds.json")
expected_json = json.load(file_json)
Expand Down
9 changes: 7 additions & 2 deletions trcli/data_classes/dataclass_testrail.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ def proper_format_for_elapsed(elapsed):
if settings.ALLOW_ELAPSED_MS:
return f"{round(elapsed, 3)}s" if float(elapsed) >= 0.001 else None
else:
rounded_secs = round(float(elapsed))
return f"{rounded_secs}s" if rounded_secs > 1 else "1s"
elapsed = float(elapsed)
if elapsed > 1:
return f"{round(elapsed)}s"
elif elapsed > 0:
return "1s"
else:
return None
except ValueError:
# unable to parse time format
elapsed = None
Expand Down

0 comments on commit eaca553

Please sign in to comment.