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

Containerise robota-core #6

Open
tcassar opened this issue May 8, 2024 · 3 comments
Open

Containerise robota-core #6

tcassar opened this issue May 8, 2024 · 3 comments

Comments

@tcassar
Copy link
Contributor

tcassar commented May 8, 2024

Running tests causes three skips if graphviz is not installed. To circumvent these problems, containerising the application with Docker would be useful and so I shall do it.

@suzanneEmbury
Copy link
Contributor

Sounds good, @tcassar . I guess most of the tests don't need graphviz, though?

Can you point me at the tests that need it?

@SauravMaheshkar
Copy link

Another viable option might be to create a decorator which checks if a particular package is installed. There are some versions of this available online, my personal favourite is source :

def has_package(package: str) -> bool:
    r"""Returns :obj:`True` in case :obj:`package` is installed."""
    if '|' in package:
        return any(has_package(p) for p in package.split('|'))

    req = Requirement(package)
    if find_spec(req.name) is None:
        return False
    module = import_module(req.name)
    if not hasattr(module, '__version__'):
        return True

    version = module.__version__
    # `req.specifier` does not support `.dev` suffixes, e.g., for
    # `pyg_lib==0.1.0.dev*`, so we manually drop them:
    if '.dev' in version:
        version = '.'.join(version.split('.dev')[:-1])

    return version in req.specifier

def withPackage(*args: str) -> Callable:
    r"""A decorator to skip tests if certain packages are not installed.
    Also supports version specification.
    """
    na_packages = set(package for package in args if not has_package(package))

    if len(na_packages) == 1:
        reason = f"Package {list(na_packages)[0]} not found"
    else:
        reason = f"Packages {na_packages} not found"

    def decorator(func: Callable) -> Callable:
        import pytest
        return pytest.mark.skipif(len(na_packages) > 0, reason=reason)(func)

    return decorator

@suzanneEmbury
Copy link
Contributor

Thanks @SauravMaheshkar - this is an interesting approach that we can keep in mind for the future, once we have dealt with some of the bigger problems.

In checking over the PR ( #13 ) I realised we had some of our commit visualisation code packaged along with robota-core, and that was why graphviz was needed. We should look at whether this is the best place for this code at some point, but in terms of this issue, I now at least understand why it needs to be installed.

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

No branches or pull requests

3 participants