github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/test/regression/daily/Example.py (about) 1 # Copyright IBM Corp. All Rights Reserved. 2 # 3 # SPDX-License-Identifier: Apache-2.0 4 # 5 6 # To run this: 7 # Install: sudo apt-get install python python-pytest 8 # Install: sudo pip install xmlrunner 9 # At command line: py.test -v --junitxml results_sample.xml Example.py 10 11 import unittest 12 import xmlrunner 13 import subprocess 14 15 TEST_PASS_STRING="RESULT=PASS" 16 17 class SampleTest(unittest.TestCase): 18 @unittest.skip("skipping") 19 def test_skipped(self): 20 ''' 21 This test will be skipped. 22 ''' 23 self.fail("I should not see this") 24 25 # This runs on ubuntu x86 laptop, but it fails when run by CI, because 26 # "bc" is not installed on the servers used for CI jobs. 27 @unittest.skip("skipping") 28 def test_SampleAdditionTestSkippedButWillPassIfInstallBC(self): 29 ''' 30 This test will pass. 31 ''' 32 result = subprocess.check_output("echo '7+3' | bc", shell=True) 33 self.assertEqual(int(result.strip()), 10) 34 35 def test_SampleStringTestWillPass(self): 36 ''' 37 This test will pass. 38 ''' 39 result = subprocess.check_output("echo '7+3'", shell=True) 40 self.assertEqual(result.strip(), "7+3") 41 42 def test_SampleScriptPassTest(self): 43 ''' 44 This test will pass because the executed script prints the RESULT=PASS string to stdout 45 ''' 46 result = subprocess.check_output("./SampleScriptPassTest.sh", shell=True) 47 self.assertIn(TEST_PASS_STRING, result) 48 49 def test_SampleScriptFailTest(self): 50 ''' 51 This test will pass because the executed script does NOT print the RESULT=PASS string to stdout 52 ''' 53 result = subprocess.check_output("./SampleScriptFailTest.sh", shell=True) 54 self.assertNotIn(TEST_PASS_STRING, result) 55 56 if __name__ == '__main__': 57 unittest.main(testRunner=xmlrunner.XMLTestRunner(output='runner-results'))