Skip to content
CodeKruPro

Check that code raises an exception in pytest

QuizEasy-MediumPython only

Which test passes only when parse_price("abc") raises ValueError with "invalid" in its message?

  • with pytest.raises(ValueError, match="invalid"): parse_price("abc")
  • assert parse_price("abc") == ValueError
  • try: parse_price("abc") except ValueError: pass
  • @pytest.mark.raises(ValueError)

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in