From 5c88717c33fae68b64456eb5d34f89128f1b6977 Mon Sep 17 00:00:00 2001 From: pwwang Date: Sat, 20 Jul 2024 18:40:23 -0700 Subject: [PATCH] test: try fixing "previous item was not torn down properly" (pytest-dev/pytest-forked#67) --- tests/test_proc.py | 120 ++++++++++++++++++++++----------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/tests/test_proc.py b/tests/test_proc.py index 53dfa7fb..2fa809ea 100644 --- a/tests/test_proc.py +++ b/tests/test_proc.py @@ -22,58 +22,6 @@ ) -def test_proc_repr(): - assert repr(SimpleProc) == "" - - -def test_from_proc_no_name(): - procs = [None] - with pytest.raises(PipenOrProcNameError): - procs[0] = Proc.from_proc(SimpleProc) - - -def test_from_proc(): - proc = Proc.from_proc( - SimpleProc, - name="new_proc", - desc="new desc", - envs={"a": 1}, - cache=True, - forks=2, - plugin_opts={"p": 1}, - scheduler="sge", - scheduler_opts={"s": 1}, - error_strategy="retry", - num_retries=10, - submission_batch=3, - ) - assert proc.name == "new_proc" - assert proc.desc == "new desc" - assert proc.envs == {"a": 1} - assert proc.cache - assert proc.forks == 2 - assert proc.plugin_opts == {"p": 1} - assert proc.scheduler == "sge" - assert proc.scheduler_opts == {"s": 1} - assert proc.error_strategy == "retry" - assert proc.num_retries == 10 - assert proc.submission_batch == 3 - - -def test_cached_run(caplog, pipen): - NormalProc.nexts = [] - # force uncache NormalProc - # shutil.rmtree(pipen.config.workdir) - ret = pipen.set_start(NormalProc).run() - assert ret - - # trigger caching - ret = pipen.set_start(NormalProc).run() - assert ret - - assert caplog.text.count("Cached jobs:") == 1 - - @pytest.mark.forked def test_more_nexts(pipen): proc1 = Proc.from_proc(NormalProc) @@ -112,14 +60,6 @@ def test_proc_with_input_callable(pipen): assert proc2.output_data.equals(pandas.DataFrame({"output": ["2"]})) -def test_proc_is_singleton(pipen): - pipen.workdir = ".pipen/" - os.makedirs(pipen.workdir, exist_ok=True) - p1 = SimpleProc(pipen) - p2 = SimpleProc(pipen) - assert p1 is p2 - - @pytest.mark.forked def test_ignore_input_data_of_start_proc(caplog, pipen): proc = Proc.from_proc(NormalProc, input_data=[1]) @@ -160,6 +100,66 @@ def test_script_file_exists(pipen): pipen.set_starts(ScriptNotExistsProc).run() +def test_proc_repr(): + assert repr(SimpleProc) == "" + + +def test_from_proc_no_name(): + procs = [None] + with pytest.raises(PipenOrProcNameError): + procs[0] = Proc.from_proc(SimpleProc) + + +def test_from_proc(): + proc = Proc.from_proc( + SimpleProc, + name="new_proc", + desc="new desc", + envs={"a": 1}, + cache=True, + forks=2, + plugin_opts={"p": 1}, + scheduler="sge", + scheduler_opts={"s": 1}, + error_strategy="retry", + num_retries=10, + submission_batch=3, + ) + assert proc.name == "new_proc" + assert proc.desc == "new desc" + assert proc.envs == {"a": 1} + assert proc.cache + assert proc.forks == 2 + assert proc.plugin_opts == {"p": 1} + assert proc.scheduler == "sge" + assert proc.scheduler_opts == {"s": 1} + assert proc.error_strategy == "retry" + assert proc.num_retries == 10 + assert proc.submission_batch == 3 + + +def test_cached_run(caplog, pipen): + NormalProc.nexts = [] + # force uncache NormalProc + # shutil.rmtree(pipen.config.workdir) + ret = pipen.set_start(NormalProc).run() + assert ret + + # trigger caching + ret = pipen.set_start(NormalProc).run() + assert ret + + assert caplog.text.count("Cached jobs:") == 1 + + +def test_proc_is_singleton(pipen): + pipen.workdir = ".pipen/" + os.makedirs(pipen.workdir, exist_ok=True) + p1 = SimpleProc(pipen) + p2 = SimpleProc(pipen) + assert p1 is p2 + + def test_invalid_name(): with pytest.raises(PipenOrProcNameError): Proc.from_proc(SimpleProc, name="a b")