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

Multiple tests in tests/test_config.py are broken #776

Open
carlescufi opened this issue Jan 1, 2025 · 2 comments · May be fixed by #777
Open

Multiple tests in tests/test_config.py are broken #776

carlescufi opened this issue Jan 1, 2025 · 2 comments · May be fixed by #777
Labels
bug Something isn't working

Comments

@carlescufi
Copy link
Member

The following construct used pervasively in tests/test_config.py:

    with pytest.raises(subprocess.CalledProcessError) as e:
        cmd('...')
        assert 'error string' in str(e)

but this doesn't work for two reasons:

  1. The assert statement must be outside the context manager (i.e. dedented one level) for it to execute at all if the exception is raised
  2. The error string is very often not part of the exception object, so one needs to check the captured stderr instead

Something like this works instead:

    with pytest.raises(subprocess.CalledProcessError) as exc_info:
        cmd('...', stderr=subprocess.STDOUT)
    err_msg = exc_info.value.output.decode("utf-8")
    assert 'str' in err_msg
@carlescufi carlescufi added the bug Something isn't working label Jan 1, 2025
@marc-hb
Copy link
Collaborator

marc-hb commented Jan 3, 2025

Thanks @carlescufi ! Could you submit "quick" fixes for the "easy" ones? Leave the more complex ones for later / someone with more spare time. As far as test coverage is concerned, quantity matters!

@marc-hb
Copy link
Collaborator

marc-hb commented Jan 3, 2025

If you could add a FIXME #776 next to the harder ones that would be the icing on the cake :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants