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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:29:01+00:00 2026-05-11T06:29:01+00:00

How can I make python’s unittest module show output for every assertion, rather than

  • 0

How can I make python’s unittest module show output for every assertion, rather than failing at the first one per test case? It would be much easier to debug if I could see the complete pattern of failures rather than just the first one.

In my case the assertions are based on a couple loops over an array containing an object plus some function names and the expected output (see below), so there isn’t an obvious way (at least to me) to just separate every assertion into a separate TestCase:

import unittest import get_nodes  class mytest2(unittest.TestCase):     def testfoo(self):         root = get_nodes.mmnode_plus.factory('mytree.xml')          tests = [             (root, {'skip_traversal': False, 'skip_as_child': True, 'skip_as_parent': False, 'is_leaf': False}),             (root[0], {'skip_traversal': False, 'skip_as_child': False, 'skip_as_parent': False, 'is_leaf': False}),             (root[1], {'skip_traversal': True, 'skip_as_child': True, 'skip_as_parent': True}),             (root[1][0], {'skip_traversal': True}),             (root[0][0], {'is_leaf': False, 'skip_traversal': False, 'skip_as_child': False, 'skip_as_parent': False}),             (root[0][0][0], {'is_leaf': True, 'skip_traversal': False, 'skip_as_child': False, 'skip_as_parent': True}),             (root[0][4], {'skip_traversal': True, 'skip_as_child': True, 'skip_as_parent': True}),             (root[0][7], {'skip_traversal': False, 'skip_as_child': False, 'skip_as_parent': True}),         ]                 for (node, states) in tests:             for test_state, exp_result in states.iteritems():                 self.assertEqual(node.__getattribute__(test_state)(), exp_result, 'unexpected %s for state %s of node %s %s' % (not exp_result, test_state, repr(node), repr(node.__dict__)))  unittest.main() 

obj.__getattribute__('hello') returns obj.hello so node.__getattribute__(test_state)() is my way of calling the member function of node whose name is stored in the test_state variable.

  • 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. 2026-05-11T06:29:02+00:00Added an answer on May 11, 2026 at 6:29 am

    I was able to do it by making new TestCase classes dynamically using the builtin type() factory:

    root = get_nodes.mmnode_plus.factory('somenodes.xml')  tests = [     (root, {'skip_traversal': False, 'skip_as_child': True, 'skip_as_parent': False, 'is_leaf': False}),     (root[0], {'skip_traversal': False, 'skip_as_child': False, 'skip_as_parent': False, 'is_leaf': False}),     (root[1], {'skip_traversal': True, 'skip_as_child': True, 'skip_as_parent': True}),     (root[1][0], {'skip_traversal': True}),     (root[0][0], {'is_leaf': False, 'skip_traversal': False, 'skip_as_child': False, 'skip_as_parent': False}),     (root[0][0][0], {'is_leaf': True, 'skip_traversal': False, 'skip_as_child': False, 'skip_as_parent': True}),     (root[0][4], {'skip_traversal': True, 'skip_as_child': True, 'skip_as_parent': True}),     (root[0][7], {'skip_traversal': False, 'skip_as_child': False, 'skip_as_parent': True}), ]  i = 0 for (node, states) in tests:     for test_state, exp_result in states.iteritems():          input = node.__getattribute__(test_state)()         errstr = 'expected %s, not %s for state %s of node %s' % (input, exp_result, test_state, repr(node))          locals()['foo' + str(i)] = type('foo' + str(i), (unittest.TestCase,),             {'input': input, 'exp_result': exp_result, 'errstr': errstr, 'testme': lambda self: self.assertEqual(self.input, self.exp_result, self.errstr)})         i += 1 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think it would make more sense to use a… May 11, 2026 at 11:40 pm
  • Editorial Team
    Editorial Team added an answer In the resin docs it shows an example using regex… May 11, 2026 at 11:40 pm
  • Editorial Team
    Editorial Team added an answer In Xcode 3.2, the "Open Quickly" command (Shift-Control-D) lets you… May 11, 2026 at 11:40 pm

Related Questions

How can I make python's unittest module show output for every assertion, rather than
How can I make boost.python code python exceptions aware? For example, int test_for(){ for(;;){
How can I make an SSH connection in Python 3.0? I want to save
How can I make a keep alive HTTP request using Python's urllib2?
How can I make such a conditional search in Bash like in Google python

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.