6

I try to run Python unit tests on our continues integration server (Bamboo, running on Debian Jessie) with XML output so we can either mark build as fail or success according to the test results. I am currently struggling with the fact that I just cannot install xmlrunner module. This is what I have done

sudo apt-get install python-xmlrunner
python3 
>>> import xmlrunner 
ImportError: No module named 'xmlrunner'

So I tried pip but it says package is already installed

sudo pip install unittest-xml-reporting
Requirement already satisfied (use --upgrade to upgrade): unittest-xml-reporting in /usr/lib/python2.7/dist-packages

Btw I can import this module with Python 2.7 which probably means that this python-xmlrunner package is installed only for 2.7 version.

And I run my test class through python3 -m unittest discover project_name with main method likes this unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))

0

3 Answers 3

4

You should install the runner using pip, and I think the package is just called xmlrunner (but maybe that is python 2.7)

pip install xmlrunner

Even better would be to everything inside virtualenv. Then you can pass a requirements.txt with all your dependencies, and you do not need to sudo install anything. Then you can choose any python version you like, isolated from your global installation.

If you wnat to check if it is installed, and which version, use pip freeze

EDIT If pip install xmlrunner does not work, try pip install unittest-xml-reporting. Thanks, @scrutari

Sign up to request clarification or add additional context in comments.

Comments

0

When I had this problem, I was able to fix it by putting the following line above the import statements:

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

Comments

0

Usually we run tests using python -m unittest If you used similar approach, it will run your test cases, but it won't generate XML file. So run your code like python test.py.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.