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

  • SEARCH
  • Home
  • 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 8919083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:55:34+00:00 2026-06-15T05:55:34+00:00

Possible Duplicate: How do you test that a Python function throws an exception? I

  • 0

Possible Duplicate:
How do you test that a Python function throws an exception?

I have to do white-box and black-box testing so i`m wondering how it is possible to test a function that trows an exceptions, like this one

class validator_client():

    def validate_client(self,client):
        erori=[]
        if client.get_identitate()=="":
            erori.append("Nu exista ID!")
        if client.get_nume()=="":
            erori.append("Nu exista nume!")
        if (client.get_filme_inchiriate()!="da" ) and (client.get_filme_inchiriate()!="nu") :
            erori.append("Campul 'Filme inchiriate' completat gresit!")
        if len(erori)>0:
            raise ValidatorException(erori)

I`ve read something about assertRises() but i can not import the module with this method, found this on stackowerflow:

from testcase import TestCase

import mymod

class MyTestCase(TestCase):
    def test1(self):
        self.assertRaisesWithMessage(SomeCoolException,
                                     'expected message',
                                      mymod.myfunc)

but I`m not able to make it work.

  • 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-06-15T05:55:36+00:00Added an answer on June 15, 2026 at 5:55 am

    This is a working example that is a simplified version of what you will find in the python docs. It checks that random.shuffle raises a TypeError exception.

    import random, unittest
    
    class TestSequenceFunctions(unittest.TestCase):
        def test_shuffle(self):
            self.assertRaises(TypeError, random.shuffle, (1,2,3))
    
    unittest.main()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Calling Python from JavaScript I have a test.py and test.js . I
Possible Duplicate: Best practices in error reporting (Mathematica) Assume that I have a function
Possible Duplicate: Timeout on a Python function call I want to implement that when
Possible Duplicate: typeof for RegExp I have a routine that is testing to see
Possible Duplicate: How do you generate dynamic (parameterized) unit tests in Python? I have
Possible Duplicate: accelerometer in Android emulator I have an application that plays music when
Possible Duplicate: Extracting indices for data frame rows that have MAX value for named
Possible Duplicate: file_put_contents permission denied I have recently transferred server, and it seems that
Possible Duplicate: Why can’t I catch a generic exception in C#? I have been
Possible Duplicate: How should I unit test threaded code? The classical unit testing is

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.