Using testr unable to discover native python test-scripts

Asked by puppet-py

I am newbie to testr.

I have a package with following directory and coding structure:

testpkg
------------
     |
     |
     |__init__.py
     |
     |--- libraries for the testcases(3 such files)
     |
     | --- test suite files
           |
           | -- testclass(name same as test_suite filename)
                      |-- each testcase is a definition inside the testclass

With above structure, I want to run the testcases using testr.

If I define the '.testr.conf' as below, then it runs all the tests inside the testsuite 'tc_pc' but reports FAILED, although the testsuite has ALL PASSED testcases. I am suspecting that testr expects a returncode which my testsuite is not returning
[DEFAULT]
test_command=python tc_pc.py discover . $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list

If I want to testr to discover all testuites or testcases available in the 'testpkg', then it does not discover any testcase, because nothing is returned on 'testr list-tests' . Here is my config

[DEFAULT]
test_command=python -m subunit.run discover testpkg $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list

Btw.. I am running testr from the 'testpkg' directory

What changes or what am I need to correct to achieve what I intend to do ? Any input

Question information

Language:
English Edit question
Status:
Answered
For:
testtools Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
puppet-py (jbanerje) said :
#1

This is not a bug but a question

Revision history for this message
Robert Collins (lifeless) said :
#2

Hi, so if testr reports failed, it means that the underlying test backend (in your case "python tc_pc.py discover . ....") has exited non-zero.

What is tc_pc.py?

The easiest way to debug this is to start with 'python -m testtools.run discover --list .' and see what it returns. If it doesn't return your tests, then thats what needs fixing.

You should run these commands from the root of your source tree - the directory above testpkg usually.

Revision history for this message
puppet-py (jbanerje) said :
#3

Thanks Robert.. MY apologies for the delay in my response.

'tc_pc.py' is the testsuite file which has bunch of testcases as methods in the testsuite class.. something like:

class test_pc(object):
   def test_1(self):
   def test_2(self):
   def run(self):
     self.test_1()
     self.test_1()

Now when I run this 'python -m testtools.run discover --list .' on the directory above testpkg, then it returns nothing.

So my lame question to you: what should I be fixing.. is it my test definitions/test structuring .. Any guidance from you will be great

Revision history for this message
Robert Collins (lifeless) said :
#4

Your test class needs to derive from unittest.TestCase for test discovery to find it.

Can you help with this problem?

Provide an answer of your own, or ask puppet-py for more information if necessary.

To post a message you must log in.