Python Forum
Odd Unit Test Behavior - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Odd Unit Test Behavior (/thread-23483.html)



Odd Unit Test Behavior - ichabod801 - Jan-01-2020

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. : )


RE: Odd Unit Test Behavior - Gribouillis - Jan-02-2020

It looks as if self.bot is not sufficiently isolated from the rest. Is it instanciated in a setUp() method?


RE: Odd Unit Test Behavior - ichabod801 - Jan-02-2020

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.


RE: Odd Unit Test Behavior - ichabod801 - Jan-02-2020

Nope. Making sure everything was a copy or a deep copy did not change the problem.