Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Odd Unit Test Behavior
#1
I have this program:

"""
_test_all.py

Overall unit testing for the t_games project.
"""

import unittest

if __name__ == '__main__':
	test_suite = unittest.defaultTestLoader.discover('.', pattern = '*_test.py')
	unittest.TextTestRunner(verbosity = 1).run(test_suite)
This is in a folder with a bunch of other test code files. When I run it, I get two errors in the file interface_test.py:

Output:
====================================================================== ERROR: testAliasStatsTitle (t_games.t_tests.interface_test.InterfaceDoStatsTest) Test call arguments for Interface.do_stats for a specific game alias. ---------------------------------------------------------------------- Traceback (most recent call last): File "C:\Users\Craig\Documents\t_games\t_tests\interface_test.py", line 184, in testAliasStatsTitle self.assertIn('\nUnit Statistics\n', self.bot.info[0]) IndexError: list index out of range ====================================================================== FAIL: testAliasStatsAllGames (t_games.t_tests.interface_test.InterfaceDoStatsTest) Test stat groups shown for Interface.do_stats for a specific game alias. ---------------------------------------------------------------------- Traceback (most recent call last): File "C:\Users\Craig\Documents\t_games\t_tests\interface_test.py", line 179, in testAliasStatsAllGames self.assertEqual(1, len(self.bot.info)) AssertionError: 1 != 0
Note that self.bot is a dummy class, that stores any text sent to it in the info attribute. Normally this text would be sent to a class that would print the text. So I'm testing printing some text, and it appears to not be printing.

So I next run interface_test.py, because the full _test_all.py takes a half hour or more. The idea being to work on the problem, rerunning itnerface_test.py as I go to check on my progress, and then rerunning the full _test_all.py at the end to confirm the problem is solved.

The problem is that when I run interface_test.py, the tests don't cause an error. I'm running both programs from the same location using the command line: python t_games\t_tests\_test_all.py or python t_games\t_tests\interface_test.py. I've been running the tests in 2.7 (t_games is designed to be 2.7 and 3.x compatible). I just started the full run in 3.6 to see if I get the same issue there.

Any ideas as to the discrepancy?

Edit: All tests are running fine in 3.6.3, whether I run _test_all.py or interface_test.py. Ha! Unsupported for less than 24 hours and it's already causing me problems. : )
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#2
It looks as if self.bot is not sufficiently isolated from the rest. Is it instanciated in a setUp() method?
Reply
#3
Yup. But along those lines there are two other object those tests depend on, preset test results and dummy game categories. These may not be sufficiently isolated. Let me try that.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#4
Nope. Making sure everything was a copy or a deep copy did not change the problem.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unit Testing Set Up and Use RockBlok 2 422 Jan-08-2024, 07:43 PM
Last Post: deanhystad
  How to test and import a model form computer to test accuracy using Sklearn library Anldra12 6 3,110 Jul-03-2021, 10:07 AM
Last Post: Anldra12
  Writing unit test results into a text file ateestructural 3 4,732 Nov-15-2020, 05:41 PM
Last Post: ateestructural
  How to write test cases for a init function by Unit test in python? binhduonggttn 2 3,103 Feb-24-2020, 12:06 PM
Last Post: Larz60+
  How to write test cases by Unit test for database configuration file? binhduonggttn 0 2,549 Feb-18-2020, 08:03 AM
Last Post: binhduonggttn
  Remove function and unit test ftg 5 3,528 Jan-07-2020, 03:10 PM
Last Post: ndc85430
  Define unit of measure of a number doug2019 3 2,371 Oct-15-2019, 03:43 PM
Last Post: jefsummers
  Unit testing - AssertRaises kerzol81 3 4,557 Oct-07-2019, 10:35 AM
Last Post: buran
  unit test roll die saladgg 5 4,161 Nov-06-2018, 11:39 PM
Last Post: stullis
  Would you unit test __init__ method? kilthar 1 30,983 Oct-18-2017, 05:31 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020