From 5b88afc7c67745f352d0c9ff5c0e5acfcbd971ca Mon Sep 17 00:00:00 2001 From: Kieran Prasch Date: Fri, 11 Dec 2020 12:27:48 -0800 Subject: [PATCH] localizes card mocking fixture so CLI test modules will propery run. --- tests/acceptance/cli/test_contacts.py | 13 +++++++++++++ tests/conftest.py | 15 --------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/tests/acceptance/cli/test_contacts.py b/tests/acceptance/cli/test_contacts.py index 192dbf8cd..e73f39f98 100644 --- a/tests/acceptance/cli/test_contacts.py +++ b/tests/acceptance/cli/test_contacts.py @@ -18,12 +18,25 @@ import os import pytest +import tempfile +from pathlib import Path from umbral.keys import UmbralPrivateKey from nucypher.cli.main import nucypher_cli from nucypher.policy.identity import Card +@pytest.fixture(scope='module', autouse=True) +def patch_card_directory(session_mocker): + custom_filepath = '/tmp/nucypher-test-cards-' + tmpdir = tempfile.TemporaryDirectory(prefix=custom_filepath) + tmpdir.cleanup() + session_mocker.patch.object(Card, 'CARD_DIR', return_value=Path(tmpdir.name), + new_callable=session_mocker.PropertyMock) + yield + tmpdir.cleanup() + + @pytest.fixture(scope='module') def alice_verifying_key(): return UmbralPrivateKey.gen_key().get_pubkey().hex() diff --git a/tests/conftest.py b/tests/conftest.py index a88d0324b..aaa3da48c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -15,19 +15,15 @@ You should have received a copy of the GNU Affero General Public License along with nucypher. If not, see . """ - from collections import defaultdict import lmdb import pytest -import tempfile -from pathlib import Path from nucypher.characters.control.emitters import WebEmitter from nucypher.crypto.powers import TransactingPower from nucypher.network.nodes import Learner from nucypher.network.trackers import AvailabilityTracker -from nucypher.policy.identity import Card from nucypher.utilities.logging import GlobalLoggerSettings from tests.constants import INSECURE_DEVELOPMENT_PASSWORD from tests.mock.datastore import mock_lmdb_open @@ -192,17 +188,6 @@ def check_character_state_after_test(request): tracker.work_tracker.stop() -@pytest.fixture(scope='session', autouse=True) -def patch_card_directory(session_mocker): - custom_filepath = '/tmp/nucypher-test-cards-' - tmpdir = tempfile.TemporaryDirectory(prefix=custom_filepath) - tmpdir.cleanup() - session_mocker.patch.object(Card, 'CARD_DIR', return_value=Path(tmpdir.name), - new_callable=session_mocker.PropertyMock) - yield - tmpdir.cleanup() - - @pytest.fixture(scope='session', autouse=True) def mock_datastore(monkeysession): monkeysession.setattr(lmdb, 'open', mock_lmdb_open)