Skip to content

Commit

Permalink
CLEANUP: Remove tempfile module usage
Browse files Browse the repository at this point in the history
* Use pytest tmp_path fixture instead
  • Loading branch information
jenisys committed Apr 22, 2023
1 parent dbfffd4 commit aa26f08
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions tests/unit/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import os.path
import sys
import warnings
import tempfile
import unittest
import six
from six import StringIO
Expand Down Expand Up @@ -623,18 +622,18 @@ def test_teardown_capture_removes_log_tap(self):

r.capture_controller.log_capture.abandon.assert_called_with()

def test_exec_file(self):
fn = tempfile.mktemp()
with open(fn, "w") as f:
def test_exec_file(self, tmp_path):
filename = tmp_path/"example.py"
with open(filename, "w") as f:
f.write("spam = __file__\n")
g = {}
l = {}
runner_util.exec_file(fn, g, l)
assert "__file__" in l
my_globals = {}
my_locals = {}
runner_util.exec_file(filename, my_globals, my_locals)
assert "__file__" in my_locals
# pylint: disable=too-many-format-args
assert "spam" in l, '"spam" variable not set in locals (%r)' % (g, l)
assert "spam" in my_locals, '"spam" variable not set in locals (%r)' % (my_globals, my_locals)
# pylint: enable=too-many-format-args
assert l["spam"] == fn
assert my_locals["spam"] == filename

def test_run_returns_true_if_everything_passed(self):
r = runner.Runner(Mock())
Expand Down

0 comments on commit aa26f08

Please sign in to comment.