From 2d8d1d6d32ce7fbe901ddeeb49417da0d0458af9 Mon Sep 17 00:00:00 2001 From: Ogi Moore Date: Sun, 25 Apr 2021 20:53:50 -0700 Subject: [PATCH] Add tmp_module fixture for test_reload --- pyqtgraph/tests/conftest.py | 10 ++++++++++ pyqtgraph/tests/test_reload.py | 15 +++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 pyqtgraph/tests/conftest.py diff --git a/pyqtgraph/tests/conftest.py b/pyqtgraph/tests/conftest.py new file mode 100644 index 00000000..01b08995 --- /dev/null +++ b/pyqtgraph/tests/conftest.py @@ -0,0 +1,10 @@ +import pytest +import os +import sys + +@pytest.fixture +def tmp_module(tmp_path): + module_path = os.fsdecode(tmp_path) + sys.path.insert(0, module_path) + yield module_path + sys.path.remove(module_path) diff --git a/pyqtgraph/tests/test_reload.py b/pyqtgraph/tests/test_reload.py index fe2f2eb9..495a3f9d 100644 --- a/pyqtgraph/tests/test_reload.py +++ b/pyqtgraph/tests/test_reload.py @@ -1,4 +1,4 @@ -import tempfile, os, sys, shutil, time +import os, sys, shutil, time import pyqtgraph as pg import pyqtgraph.reload import pytest @@ -35,11 +35,10 @@ def remove_cache(mod): or (sys.version_info >= (3, 10)), reason="Unknown Issue" ) -def test_reload(): - py3 = sys.version_info >= (3,) - +@pytest.mark.usefixtures("tmp_module") +def test_reload(tmp_module): # write a module - mod = os.path.join(path, 'reload_test_mod.py') + mod = os.path.join(tmp_module, 'reload_test_mod.py') print("\nRELOAD FILE:", mod) with open(mod, "w") as file_: file_.write(code.format(path_repr=pgpath_repr, msg="C.fn() Version1")) @@ -57,7 +56,7 @@ def test_reload(): file_.write(code.format(path_repr=pgpath_repr, msg="C.fn() Version 2")) time.sleep(1.1) #remove_cache(mod) - result1 = pg.reload.reloadAll(path, debug=True) + _ = pg.reload.reloadAll(tmp_module, debug=True) v2 = (reload_test_mod.C, reload_test_mod.C.sig, reload_test_mod.C.fn, c.sig, c.fn, c.fn.__func__) oldcfn = pg.reload.getPreviousVersion(c.fn) @@ -73,8 +72,8 @@ def test_reload(): file_.write(code.format(path_repr=pgpath_repr, msg="C.fn() Version2")) time.sleep(1.1) # remove_cache(mod) - result2 = pg.reload.reloadAll(path, debug=True) - v3 = (reload_test_mod.C, reload_test_mod.C.sig, reload_test_mod.C.fn, c.sig, c.fn, c.fn.__func__) + _ = pg.reload.reloadAll(tmp_module, debug=True) + _ = (reload_test_mod.C, reload_test_mod.C.sig, reload_test_mod.C.fn, c.sig, c.fn, c.fn.__func__) cfn1 = pg.reload.getPreviousVersion(c.fn) cfn2 = pg.reload.getPreviousVersion(cfn1)