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

docs: Development Setup should include yubikey dependency #501

Open
lukpueh opened this issue Aug 13, 2024 · 2 comments
Open

docs: Development Setup should include yubikey dependency #501

lukpueh opened this issue Aug 13, 2024 · 2 comments
Labels
good first issue Good for newcomers

Comments

@lukpueh
Copy link

lukpueh commented Aug 13, 2024

I'd expect that running the installation instructions from "Development Setup" would allow to run pytest. This is not the case:

$ pip install -e .[dev]
$ pip install -e .[test]
$ pytest

=================================================================== ERRORS ====================================================================
___________________________________ ERROR collecting taf/tests/test_repository_tool/test_repository_tool.py ___________________________________
ImportError while importing test module '/Users/lukp/tuf/taf/taf/tests/test_repository_tool/test_repository_tool.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../.pyenv/versions/3.12.4/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
taf/tests/test_repository_tool/test_repository_tool.py:9: in <module>
    import taf.yubikey as yk
taf/yubikey.py:17: in <module>
    from ykman.device import list_all_devices
E   ModuleNotFoundError: No module named 'ykman'

Installing with yubikey extra does the trick: pip install -e .[dev,test,yubikey] (although the yubikey dependency should probably be part of the test extras, if tests need it)

@renatav renatav added the good first issue Good for newcomers label Aug 22, 2024
@renatav
Copy link
Collaborator

renatav commented Aug 22, 2024

Handle the import similarly to how we handle it in other modules. That should do the trick

@renatav
Copy link
Collaborator

renatav commented Oct 3, 2024

So what we need to do here is update taf\taf\tests\test_repository_tool\test_repository_tool.py. If you install yubikey-manager dependency, (install taf by running pip install -e .[yubikey] from the root of the repository), you should be able to run this test using pytest. Then, uninstall yubikey-manager: pip uninstall yubikey-manager. You see this error:

ImportError while loading conftest 'D:\oll\taf\taf\tests\test_repository_tool\conftest.py'.
conftest.py:8: in
from taf.tools.yubikey.yubikey_utils import (
....\tools\yubikey_init_.py:3: in
from taf.api.yubikey import export_yk_certificate, export_yk_public_pem, get_yk_roles, setup_signing_yubikey, setup_test_yubikey
....\api\yubikey.py:14: in
import taf.yubikey as yk
....\yubikey.py:17: in
from ykman.device import list_all_devices
E ModuleNotFoundError: No module named 'ykman'
If you take a closer look at it, there is a import taf.yubikey as yk in this module, but also there are imports from taf.tools.yubikey.yubikey_utils in that conftests (conftest in the same package). The easiest way to fix this would be to create a new package, say test_repository_tool_w_yubikey or something like that. Create a conftest inside that package and then move everything that requires a yubukey to that conftest. E.g. fixtures like

@fixture
def targets_yk(pytestconfig):
"""Targets YubiKey."""
return TargetYubiKey(KEYSTORE_PATH, pytestconfig.option.signature_scheme)
Move everything from test_repository_tool to that a module inside this new package. Then skip the whole module if the dependency is not installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants