About 555,000 results
Open links in new tab
  1. What is the use of "assert" in Python? - Stack Overflow

    Feb 28, 2011 · Python’s assert statement is a debugging aid, not a mechanism for handling run-time errors. The goal of using assertions is to let developers find the likely root cause of a bug …

  2. python - Best practice for using assert? - Stack Overflow

    Is there a performance or code maintenance issue with using assert as part of the standard code instead of using it just for debugging purposes? Is assert x >= 0, 'x is less than zero' better or

  3. Making Python's `assert` throw an exception that I choose

    Can I make assert throw an exception that I choose instead of AssertionError? UPDATE: I'll explain my motivation: Up to now, I've had assertion-style tests that raised my own exceptions; …

  4. python - How do I properly assert that an exception gets raised in ...

    I have to reiterate @Ctrl-C's comment: pytest.mark.xfail DOES NOT assert that an exception was raised, it simply allows it to be raised. This is not what the title of the question asks.

  5. python - What's the difference between raise, try, and assert?

    108 I have been learning Python and the raise function* and assert are really similar (what I realised is that both of them crash the app, unlike try - except) and I can't see a situation …

  6. Assert that a method was called in a Python unit test

    37 Yes if you are using Python 3.3+. You can use the built-in unittest.mock to assert method called. For Python 2.6+ use the rolling backport Mock, which is the same thing. Here is a quick …

  7. python - Why assert is not largely used? - Stack Overflow

    I just mentioned those projects because they are very representative on python community and is supposed that contains good practices of python coding. I'm not trying to understand why they …

  8. How to assert two list contain the same elements in Python?

    When writing test cases, I often need to assert that two list contain the same elements without regard to their order. I have been doing this by converting the lists to sets. Is there any simpler...

  9. python - Assert that a method was called with one argument out …

    The following one liner will assert that requests_arguments appears at least once in the list of positional arguments made to the calls of requests.post assert any(map(lambda args: …

  10. python - Assert a function/method was not called using Mock

    I'm using the Mock library to test my application, but I want to assert that some function was not called. Mock docs talk about methods like mock.assert_called_with and …