Test describing crash behaviour when tests package is unavailable

pull/2013/head
Kieran Prasch 2020-05-19 21:55:19 -07:00
parent 3155b966c7
commit ba81356224
No known key found for this signature in database
GPG Key ID: 199AB839D4125A62
1 changed files with 33 additions and 0 deletions

33
tests/test_package.py Normal file
View File

@ -0,0 +1,33 @@
import builtins
import pytest
from nucypher.exceptions import DevelopmentInstallationRequired
def test_development_install_required(capsys, mocker):
real_import = builtins.__import__
def mock_import(name, *args, **kwargs):
if 'tests' in name:
raise ImportError
return real_import(name, *args, **kwargs)
# Test lazy imports for entities that depends on the tests package
try:
builtins.__import__ = mock_import
# For example...
from nucypher.characters.unlawful import Vladimir # Import OK
with pytest.raises(DevelopmentInstallationRequired): # Lazy Action
Vladimir.from_target_ursula(target_ursula=mocker.Mock())
from nucypher.blockchain.eth.providers import _get_pyevm_test_backend
with pytest.raises(DevelopmentInstallationRequired):
_get_pyevm_test_backend()
from nucypher.characters.control.controllers import JSONRPCController
with pytest.raises(DevelopmentInstallationRequired):
JSONRPCController.test_client(self=mocker.Mock())
finally:
builtins.__import__ = real_import