Re: assertraises behaviour

Discussion in 'Python' started by andrea crotti, Jul 17, 2012.

  1. 2012/7/16 Peter Otten <>:
    > No, I don't see how the code you gave above can fail with an OSError.
    >
    > Can you give an example that produces the desired behaviour with nose? Maybe
    > we can help you translate it to basic unittest.
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list



    Well this is what I meant:

    import unittest

    class TestWithRaises(unittest.TestCase):
    def test_first(self):
    assert False

    def test_second(self):
    print("also called")
    assert True

    if __name__ == '__main__':
    unittest.main()

    in this case also the second test is run even if the first fails..
    But that's probably easy because we just need to catch exceptions for
    every method call, so it's not exactly the same thing..
     
    andrea crotti, Jul 17, 2012
    #1
    1. Advertising

  2. Am 17.07.2012 11:06, schrieb andrea crotti:
    > import unittest
    >
    > class TestWithRaises(unittest.TestCase):
    > def test_first(self):
    > assert False
    >
    > def test_second(self):
    > print("also called")
    > assert True
    >
    > if __name__ == '__main__':
    > unittest.main()
    >
    > in this case also the second test is run even if the first fails..


    The reason for that is that the unit testing framework catches and
    handles the error. It calls both test functions in some unspecified
    order and logs the result. Calls to two separate test functions are
    thereby separated from each other. This is intentionally so, but I think
    you can also give the unit testing framework a flag that makes it abort
    after the first error. In no way will the exception escape from the
    unittest.main() call though, it is all caught and handled inside, also
    by intention.


    > But that's probably easy because we just need to catch exceptions for
    > every method call, so it's not exactly the same thing..


    I don't understand what you want to say here. I also don't understand
    what your problem in general is. I guess there are some expectations
    which are not satisfied, but you haven't explained those explicitly yet.

    Uli
     
    Ulrich Eckhardt, Jul 17, 2012
    #2
    1. Advertising

  3. > > import unittest

    > >
    > > class TestWithRaises(unittest.TestCase):
    > > def test_first(self):
    > > assert False
    > >
    > > def test_second(self):
    > > print("also called")
    > > assert True
    > >
    > > if __name__ == '__main__':
    > > unittest.main()
    > >
    > > in this case also the second test is run even if the first fails..

    >
    > The reason for that is that the unit testing framework catches and
    > handles the error. It calls both test functions in some unspecified
    > order and logs the result. Calls to two separate test functions are
    >thereby separated from each other. This is intentionally so, but I think
    > you can also give the unit testing framework a flag that makes it abort
    > after the first error. In no way will the exception escape from the
    > unittest.main() call though, it is all caught and handled inside, also
    > by intention.
    >
    >

    > > But that's probably easy because we just need to catch exceptions for
    > > every method call, so it's not exactly the same thing..

    >
    > I don't understand what you want to say here. I also don't understand
    > what your problem in general is. I guess there are some expectations
    > which are not satisfied, but you haven't explained those explicitly yet.
    >


    I think Andrea wants to do the same thing but with nose andnot
    unittest.

    Ramit

    This email is confidential and subject to important disclaimers and
    conditions including on offers for the purchase or sale of
    securities, accuracy and completeness of information, viruses,
    confidentiality, legal privilege, and legal entity disclaimers,
    available at http://www.jpmorgan.com/pages/disclosures/email.
     
    Prasad, Ramit, Jul 17, 2012
    #3
  4. On 17/07/2012 18:49, Prasad, Ramit wrote:
    >>> import unittest
    >>>
    >>> class TestWithRaises(unittest.TestCase):
    >>> def test_first(self):
    >>> assert False
    >>>
    >>> def test_second(self):
    >>> print("also called")
    >>> assert True
    >>>
    >>> if __name__ == '__main__':
    >>> unittest.main()
    >>>
    >>> in this case also the second test is run even if the first fails..

    >>
    >> The reason for that is that the unit testing framework catches and
    >> handles the error. It calls both test functions in some unspecified
    >> order and logs the result. Calls to two separate test functions are
    >> thereby separated from each other. This is intentionally so, but I think
    >> you can also give the unit testing framework a flag that makes it abort
    >> after the first error. In no way will the exception escape from the
    >> unittest.main() call though, it is all caught and handled inside, also
    >> by intention.
    >>
    >>
    >>> But that's probably easy because we just need to catch exceptions for
    >>> every method call, so it's not exactly the same thing..

    >>
    >> I don't understand what you want to say here. I also don't understand
    >> what your problem in general is. I guess there are some expectations
    >> which are not satisfied, but you haven't explained those explicitly yet.
    >>

    >
    > I think Andrea wants to do the same thing but with nose and not
    > unittest.
    >
    > Ramit
    >
    > This email is confidential and subject to important disclaimers and
    > conditions including on offers for the purchase or sale of
    > securities, accuracy and completeness of information, viruses,
    > confidentiality, legal privilege, and legal entity disclaimers,
    > available at http://www.jpmorgan.com/pages/disclosures/email.
    >


    Do what? Like Ulrich Eckhart I simply don't understand what she's
    getting at. Perhaps it's a problem with Englsh being a second language
    issue rather than Python itself. Thankfully I'm sure that everything
    will come out in the wash.

    --
    Cheers.

    Mark Lawrence.
     
    Mark Lawrence, Jul 17, 2012
    #4
  5. > On 17/07/2012 18:49, Prasad, Ramit wrote:

    > >>> import unittest
    > >>>
    > >>> class TestWithRaises(unittest.TestCase):
    > >>> def test_first(self):
    > >>> assert False
    > >>>
    > >>> def test_second(self):
    > >>> print("also called")
    > >>> assert True
    > >>>
    > >>> if __name__ == '__main__':
    > >>> unittest.main()
    > >>>
    > >>> inthis case also the second test is run even if the first fails..
    >>>
    > >> The reason for that is that the unit testing framework catches and
    > >> handles the error. It calls both test functions in some unspecified
    > >> order and logs the result. Calls to two separate test functions are
    > >> thereby separated from each other. This is intentionally so, but I think
    > >> you can also give the unit testing framework a flag that makes it abort
    > >> after the first error. In no way will the exception escape from the
    > >> unittest.main() call though, it is all caught and handled inside, also
    > >> by intention.
    > >>
    > >>
    > >>> But that's probably easy because we just need to catch exceptions for
    > >>> every method call, so it's not exactly the same thing..
    > >>
    > >> I don't understand what you want tosay here. I also don't understand
    > >> what your problem in generalis. I guess there are some expectations
    > >> which are not satisfied, but you haven't explained those explicitly yet.
    > >>

    > >
    > > I think Andrea wants to do the same thing but with nose and not
    > > unittest.
    > >
    > > Ramit
    > >

    >
    > Do what?Like Ulrich Eckhart I simply don't understand what she's
    > getting at. Perhaps it's a problem with Englsh being a second language
    > issue rather than Python itself. Thankfully I'm sure that everything
    >will come out in the wash.
    >
    > --
    > Cheers.
    >
    > Mark Lawrence.



    I get the impression that nose stopsrunning tests once any test
    fails instead of running all tests and listing all the tests and
    their pass/fail status (like unittest). Granted that is just what
    I get from the context as I read it as I haveno knowledge of nose.

    Ramit
    This email is confidential and subject to important disclaimers and
    conditions including on offersfor the purchase or sale of
    securities, accuracy and completeness of information, viruses,
    confidentiality, legal privilege, and legal entity disclaimers,
    available at http://www.jpmorgan.com/pages/disclosures/email.
     
    Prasad, Ramit, Jul 17, 2012
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. john
    Replies:
    2
    Views:
    2,052
  2. Inyeol
    Replies:
    3
    Views:
    342
    Chris Torek
    Oct 27, 2010
  3. andrea crotti

    Re: assertraises behaviour

    andrea crotti, Jul 16, 2012, in forum: Python
    Replies:
    0
    Views:
    191
    andrea crotti
    Jul 16, 2012
  4. Peter Otten

    Re: assertraises behaviour

    Peter Otten, Jul 16, 2012, in forum: Python
    Replies:
    0
    Views:
    195
    Peter Otten
    Jul 16, 2012
  5. Terry Reedy

    Re: assertraises behaviour

    Terry Reedy, Jul 17, 2012, in forum: Python
    Replies:
    0
    Views:
    183
    Terry Reedy
    Jul 17, 2012
Loading...

Share This Page