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

tests: config: Fix assertions checks with pytest.raises #777

Merged
merged 1 commit into from
Jan 10, 2025

Conversation

pdgendt
Copy link
Collaborator

@pdgendt pdgendt commented Jan 4, 2025

Dedent assertion checks as they were currently skipped, and make sure the correct error message is validated.

Fixes #776

marc-hb
marc-hb previously approved these changes Jan 5, 2025
@pdgendt pdgendt marked this pull request as ready for review January 5, 2025 09:59
@pdgendt
Copy link
Collaborator Author

pdgendt commented Jan 5, 2025

@carlescufi #768 might change the message with the grouped argument change, this PR can go before or after yours but might need changes accordingly.

@pdgendt pdgendt force-pushed the fix-assert-raises branch from 62a7753 to 41f201b Compare January 7, 2025 17:45
@pdgendt
Copy link
Collaborator Author

pdgendt commented Jan 7, 2025

Updated after merging #768 with updated error messages.

Copy link
Collaborator

@marc-hb marc-hb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a longer look and realized now that this does much more than moving the asserts : this also fixes the test code which of course did not work because it never ran!

That's great, but now I see a lot of repetition. Have you considered a new, generic function for negative tests? Something like:

def run_bad_cmd(cmd_str_or_list, expected_exception_type):
   with pytest.raises(expected_exception_type) as e:
       ...

   return err_msg


emsg = run_bad_cmd("config pytest", subprocess.CalledProcessError)
assert 'invalid ..." in emsg

@marc-hb marc-hb dismissed their stale review January 7, 2025 19:17

read too fast sorry

Create a helper function that captures an expected exception and returns
the output together with stderr data.

Dedent assertion checks as they were currently skipped, and make sure
the correct error message is validated.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
@pdgendt pdgendt force-pushed the fix-assert-raises branch from 41f201b to 5b12276 Compare January 8, 2025 10:07
@pdgendt pdgendt requested a review from carlescufi January 8, 2025 10:28
Copy link
Member

@carlescufi carlescufi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@carlescufi carlescufi merged commit 3ab7d2f into zephyrproject-rtos:main Jan 10, 2025
19 checks passed
@pdgendt pdgendt deleted the fix-assert-raises branch January 10, 2025 13:13
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

Successfully merging this pull request may close these issues.

Multiple tests in tests/test_config.py are broken
3 participants