3

I have a python file testing.py consisting of following:

import subprocess
import unittest
DETACHED_PROCESS = 0x00000008
def open_exe(file,mode):
    if mode == 1:
        if type(file) is str:
            object = subprocess.Popen([file],creationflags=DETACHED_PROCESS,shell=True)
        if object.pid is None:
            return 0
        else:
            print "Process id ", object.pid
            return 1
   if mode == 2:
       if type(file) is str:
           object = subprocess.Popen([file,"-configuration=" + "Other_base_0x1010.def"], creationflags=DETACHED_PROCESS,shell=True)
       if object.pid is None:
            return 0
       else:
            print "Process id ", object.pid
            return 1
    class testmyfunctions(unittest.TestCase):
       def test_contains_simple_true(self):
          self.assertEqual(open_exe("D:\\learning\\development\\MY_base.exe",1),1)              
      def test_first_process(self):
          self.assertEqual(open_exe("D:\\learning\\Projects\\Other_base.exe", 2), 1)     

if __name__ == '__main__':
    unittest.main()

This testing.py file is actualy opening two .exe's and then i have made two test cases.My question is how do i write the output of testing.py to xml file which are to be visualized on jenkins? Are there some commands ? Atleast suggest me from where to start.

1
  • try the tag --junit-xml unit_test_results.xml and check this link Commented May 20, 2015 at 12:15

2 Answers 2

1

first, install xmlrunner into your slave node. You can refer to this link along with how to use it with your unittest.

second. Back to jenkins,you need to set up a job with 2 steps:
step1: "Execute Shell" to execute your unittest, make sure you use xmlrunner to generate the xml output.
step2: "Add post-build action" ==>"Publish JUnit test report" and just put your report path(generated in step1) there.

Good luck.

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

Comments

0

You can use nosetests as your test runner. It is compatible with standard unittest tests, and has various output format options.

see: nose.readthedocs.org

To create JUnitXML, you would specify --with-xunit on the command line. So to run your tests, simply do:

$ nosetests --with-xunit

This will run your test suite, and generate a file named nosetests.xml in the current working directory.

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.