0

I have written automation test scripts using pytest framework and I am trying to run the scripts using ant build on jenkins. Please help me see my test result:

1) I have done all the installations on jenkins (python 2.7, pytest, py, pip)

2) Here is the ant build.xml file I have created

<project name="test" default="tests" basedir="tests">
<!-- Run Register test case -->
<target name="test_register">
<echo message="Executing ${TestScript}"/>
<exec dir="." executable="python">
<arg line="${TestScript}.py"/>
</exec>
</target>
<!--  Run all Test cases  -->
<target name="runAll">
<echo message="Executing ${TestScript}"/>
<exec dir="tests" executable="python">
<arg line="python *.py"/>
</exec>
</target>
</project>

3) I tried to run the build and it gives me the following output http://screencast.com/t/YxJ2NLir3dn

Please help me to correct my process and setup

Lavina
  • 3
  • 3
  • Your build output shows an import error at the test_register step, so you need to figure out how to get the required packages in your python library path (set PYTHONPATH, edit sys.path in your python script, use a virtualenv, etc). Your question doesn't provide enough detail about your code architecture to figure out how to help you with this. – Dave Bacher Apr 29 '15 at 17:43
  • I have created structure in the following way: http://screencast.com/t/ioqz97S1bL0y – Lavina Apr 30 '15 at 06:13
  • I have created structure in the following way: http://screencast.com/t/ioqz97S1bL0y ..... under pages I have locators and methods and under tests I have functions writtens – Lavina Apr 30 '15 at 06:44

1 Answers1

1

I'm just getting into python and junit tests and this seems to be a good resource

I think this is the bit you want (rather than use a test runner) add this to the end of your test file

if __name__ == '__main__':
    import xmlrunner
    unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))
Community
  • 1
  • 1
KeepCalmAndCarryOn
  • 8,817
  • 2
  • 32
  • 47
  • Hi, Thanks for your reply. So I have to add this code in every test file? and then add a "Publish JUnit test result report" post build action and fill in the "Test report XMLs" field – Lavina Apr 29 '15 at 11:09
  • You'll certainly need a publish Junit report. What you can do is look at the workspace after the job has run to see what you have got. I think I would rather use `py.test --junitxml results.xml tests.py` but not sure how you would do that with ant – KeepCalmAndCarryOn Apr 29 '15 at 11:25
  • I was able to see some report.. Atleast something better – Lavina Apr 30 '15 at 06:45