Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 815219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:38:58+00:00 2026-05-15T01:38:58+00:00

I am runninig test’s with Python Unittest. I am running tests but I want

  • 0

I am runninig test’s with Python Unittest. I am running tests but I want to do negative testing and I would like to test if a function throw’s an exception, it passes but if no exception is thrown the test fail’s. The script I have is:

    try:
        result = self.client.service.GetStreamUri(self.stream, self.token)
        self.assertFalse
    except suds.WebFault, e:                        
        self.assertTrue
    else:
        self.assertTrue

This alway’s passes as True even when the function work’s perfectly. I have also tried various other way’s including:

    try:
        result = self.client.service.GetStreamUri(self.stream, self.token)
        self.assertFalse
    except suds.WebFault, e:                        
        self.assertTrue
    except Exception, e:
        self.assertTrue

Does anyone have any suggestions?

Thanks

I have tried assertRaises with no luck.

    try:
        result = self.client.service.GetStreamUri(self.stream, self.token)
        self.assertRaises(WebFault)
    except suds.WebFault, e:                        
        self.assertFalse
    except Exception, e:                        
        self.assertTrue

It still passes. For some reason it does not try and do the assertRaises statement. I have also tried: (The function should fail but the test should pass)

    try:
        result = self.client.service.GetStreamUri(self.stream, self.token)

    except suds.WebFault, e:                        
        self.assertFalse
    except Exception, e:                        
        self.assertTrue
    else:
        self.assertFalse

For some reason even when the function passes it will not raise an error. It always no matter what goes to Exception. Unless there is an else statement then it goes to that.

Found a way that work’s but it seem’s a very poor way of doing things:

Can anyone suggest a cleaner way of doing this?

    try:
        result = self.client.service.GetStreamUri(self.stream, self.token)

    except suds.WebFault, e:                        
        self.assertFalse
    except Exception, e:
        pass

    try:
        result==result
    except:
        result=None
    if result==None:
        assert True
    else:
        assert False
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T01:38:59+00:00Added an answer on May 15, 2026 at 1:38 am

    TestCase.assertRaises is what you need however in your example you appear to be misusing it slightly. You need something like:

    def test_GetStreamUri(self):
        self.assertRaises(WebFault, self.client.service.GetStreamUri)
        result = self.client.service.GetStreamUri(self.stream, self.token)
    

    You need to tell unittest about the callable the will raise the exception before you invoke the callable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
In JUnit 3, I could get the name of the currently running test like
How can I break into a running test with the pdb interactive debugger? This
I am building an automation test suite which is running on multiple machines, all
In my C# program, I have a thread that represents a running test, which
I want to do some logging while executing my JUnit test. In JUnit 3.x
I have several projects, most of them has test target, which run tests and
Ruby 1.8.6, Rails 2.2.2, OS X Tiger My Test::Unit tests started returning the error
I'm attempting to unit test some code using NUnit. I have a method: public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.