Skip to content

Commit

Permalink
Change: Ensure test file gets deleted after test
Browse files Browse the repository at this point in the history
Create a temporary directory to put the test file in to ensure that the
test file is always deleted after the test has run.
  • Loading branch information
bjoernricks committed May 30, 2023
1 parent a98939a commit d572edf
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tests/xml/test_pretty_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from unittest.mock import patch

import defusedxml.lxml as secET
from pontos.testing import temp_directory

from gvm.errors import InvalidArgumentType
from gvm.xml import pretty_print
Expand All @@ -39,11 +40,12 @@ def test_pretty_print_to_file(self):
"</test>\n"
)

with open("test.file", "w", encoding="utf-8") as f:
pretty_print(elem, file=f)
with temp_directory() as temp_dir:
test_file = temp_dir / "test.file"
with test_file.open("w", encoding="utf-8") as f:
pretty_print(elem, file=f)

with open("test.file", "r", encoding="utf-8") as f:
xml_string = f.read()
xml_string = test_file.read_text(encoding="utf-8")

self.assertEqual(xml_string, expected_xml_string)

Expand Down

0 comments on commit d572edf

Please sign in to comment.