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

pytest with fabric example #2275

Open
TheKushIsGood opened this issue Jul 1, 2023 · 1 comment
Open

pytest with fabric example #2275

TheKushIsGood opened this issue Jul 1, 2023 · 1 comment

Comments

@TheKushIsGood
Copy link

I would like to run a pytest on few remote hosts using fabric.

Can you please provide a simple example?

@ANLHPC
Copy link

ANLHPC commented Jul 12, 2023

As a good practice, the test should be independent of the host, still it's easy to mock this, here's an example:

def test_get_groups_list_command_error(monkeypatch):
    def mock_run(*args, **kwargs):
        class Result():
            def __init__(self):
                self.stdout = ""
                self.stderr = "error"
        return Result()
    monkeypatch.setattr(Connection, "run", mock_run)

Connection above will simulate a controled run call. Which from it tests can be done depending on the Result expected results.

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

2 participants