Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pytest collection errors when anoncreds package is not installed #2750

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aries_cloudagent/anoncreds/holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
CredentialRevocationState,
Presentation,
PresentCredentials,
create_link_secret,
)
from anoncreds.bindings import create_link_secret
from aries_askar import AskarError, AskarErrorCode

from ..anoncreds.models.anoncreds_schema import AnonCredsSchema
Expand Down
25 changes: 25 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@ def stub_indy() -> Stub:
return Stub(mock.patch.dict(sys.modules, modules))


def stub_anoncreds() -> Stub:
# detect anoncreds library
try:
from anoncreds import generate_nonce

_ = generate_nonce()
return Stub(None)
except ImportError:
print("Skipping Anoncreds-specific tests: anoncreds module not installed.")
except OSError:
print(
"Skipping Anoncreds-specific tests: anoncreds shared library"
"could not be loaded."
)

modules = {}
package_name = "anoncreds"
modules[package_name] = mock.MagicMock()
return Stub(mock.patch.dict(sys.modules, modules))


def stub_askar() -> Stub:
# detect aries-askar library
try:
Expand Down Expand Up @@ -177,6 +198,7 @@ def pytest_sessionstart(session):

STUBS.update(
{
"anoncreds": stub_anoncreds(),
"askar": stub_askar(),
"indy": stub_indy(),
"indy_credx": stub_indy_credx(),
Expand All @@ -199,6 +221,9 @@ def pytest_sessionfinish(session):
def pytest_runtest_setup(item: pytest.Item):
global STUBS

if tuple(item.iter_markers(name="anoncreds")) and not STUBS["anoncreds"].found:
pytest.skip("test requires Anoncreds support")

if tuple(item.iter_markers(name="askar")) and not STUBS["askar"].found:
pytest.skip("test requires Askar support")

Expand Down
Loading