From 3b70083a0826671a8ad04d4f7e49fc3c8f0930d1 Mon Sep 17 00:00:00 2001
From: Eva Bardou <ebardou@teklia.com>
Date: Thu, 29 Apr 2021 13:11:02 +0200
Subject: [PATCH] Fix tests

---
 tests/conftest.py                           | 14 ++++----------
 tests/test_base_worker.py                   |  2 +-
 tests/test_elements_worker/test_elements.py |  2 +-
 3 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/tests/conftest.py b/tests/conftest.py
index 449572aa..83a55661 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -91,14 +91,6 @@ def setup_api(responses, monkeypatch, cache_yaml):
     monkeypatch.setenv("ARKINDEX_API_TOKEN", "unittest1234")
 
 
-@pytest.fixture(autouse=True)
-def temp_working_directory(monkeypatch, tmp_path):
-    def _getcwd():
-        return str(tmp_path)
-
-    monkeypatch.setattr(os, "getcwd", _getcwd)
-
-
 @pytest.fixture(autouse=True)
 def give_worker_version_id_env_variable(monkeypatch):
     monkeypatch.setenv("WORKER_VERSION_ID", "12341234-1234-1234-1234-123412341234")
@@ -183,9 +175,11 @@ def mock_base_worker_with_cache(mocker, monkeypatch, mock_worker_version_api):
 
 
 @pytest.fixture
-def mock_elements_worker_with_cache(monkeypatch, mock_worker_version_api):
+def mock_elements_worker_with_cache(monkeypatch, mock_worker_version_api, tmp_path):
     """Build and configure an ElementsWorker using SQLite cache with fixed CLI parameters to avoid issues with pytest"""
-    monkeypatch.setattr(sys, "argv", ["worker"])
+    cache_path = tmp_path / "db.sqlite"
+    cache_path.touch()
+    monkeypatch.setattr(sys, "argv", ["worker", "-d", str(cache_path)])
     monkeypatch.setenv("ARKINDEX_CORPUS_ID", "11111111-1111-1111-1111-111111111111")
 
     worker = ElementsWorker(support_cache=True)
diff --git a/tests/test_base_worker.py b/tests/test_base_worker.py
index acd5c557..444d5131 100644
--- a/tests/test_base_worker.py
+++ b/tests/test_base_worker.py
@@ -33,7 +33,7 @@ def test_init_with_local_cache(monkeypatch):
 
     assert worker.work_dir == os.path.expanduser("~/.local/share/arkindex")
     assert worker.worker_version_id == "12341234-1234-1234-1234-123412341234"
-    assert worker.use_cache is True
+    assert worker.support_cache is True
 
 
 def test_init_var_ponos_data_given(monkeypatch):
diff --git a/tests/test_elements_worker/test_elements.py b/tests/test_elements_worker/test_elements.py
index 018bd9cb..744009fb 100644
--- a/tests/test_elements_worker/test_elements.py
+++ b/tests/test_elements_worker/test_elements.py
@@ -145,7 +145,7 @@ def test_database_arg(mocker, mock_elements_worker, tmp_path):
         ),
     )
 
-    worker = ElementsWorker()
+    worker = ElementsWorker(support_cache=True)
     worker.configure()
 
     assert worker.use_cache is True
-- 
GitLab