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 8312961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:20:04+00:00 2026-06-08T20:20:04+00:00

I am running Python 2.6.5, so I use unittest2 module, which is the future

  • 0

I am running Python 2.6.5, so I use unittest2 module, which is the future port of the unittest module in 2.7 and 3.X. I am performing the following integration test:

def test_hits_constraint_raise(self):
    obj = Table1(...)
    self.sess.add(obj)
    self.sess.flush()

    # assert condition raises
    self.assertFailure(IntegrityError, sess.add, obj)

Instead, it hits error.

======================================================================
ERROR: test_hits_constraint_raise (__main__.TestModels)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_models.py", line 76, in test4_create_exercise_same_id_constraint_raise
    self.sess.flush()
  File "build/bdist.linux-i686/egg/sqlalchemy/orm/scoping.py", line 114, in do
    return getattr(self.registry(), name)(*args, **kwargs)
      .........
  File "build/bdist.linux-i686/egg/sqlalchemy/engine/default.py", line 331, in do_execute
    cursor.execute(statement, parameters)
IntegrityError: (IntegrityError) column exercise_id is not unique u'INSERT INTO TABLE1 (attribute1_name, attribute2_name) VALUES (?, ?)' ('value1', 'value2')

----------------------------------------------------------------------
Ran 4 tests in 0.531s

FAILED (errors=1)

Is the only way to do is use @unittest2.expectedFailure? That one will run fine.
But I want to know exactly what kind of error was raised.

----------------------------------------------------------------------
Ran 4 tests in 0.513s

OK (expected failures=1)
  • 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-08T20:20:07+00:00Added an answer on June 8, 2026 at 8:20 pm

    You can use assertRaises as a with statement context:

    with unittest.assertRaises(IntegrityError):
        sess.add(obj)
    

    More details.

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

Sidebar

Related Questions

I need to use an embedded system running Python 1.5.2+ (!!!) with very few
I wrote a python module. Running python filename.py, only checks for syntax errors. Is
When running a Python program that reads from stdin, I get the following error:
I am running python 3.1.4 from macports and I am attempting to use the
I'm trying to make Python use a Fortran DLL (call by referance). When running
I'm trying to use my fixtures in a UnitTest. AddFavoritesTestCase(unittest.TestCase): fixtures = ['/Users/Bryan/work/osqa/fixtures/fixture_questions.json'] def
I've recently started using git, and also begun unit testing (using Python's unittest module).
Question: Because of python's use of GIL is python capable running its separate threads
I'm attempting to use Python's tarfile module to extract a tar.gz archive. I'd like
I'm running python2.5 and trying to use the astLib library to analyse WCS information

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.