Skip to main content
Skip table of contents

Test Case Writing Guidelines and Examples - Python Unittest

Python unittest is a python unit test framework. Testany support this popular python test framework. This document shows how to writing a python unittest test case in Testany.

Testany test case supported python version is 3.11.5, it should compatible other lower python versions.
If a new python version needed for any specific reason, please feel free to contact our Customer Support

Test case package - one zip file
Currently we are only support upload your local zip file to Testany, the zip file need contains at least one file:

  1. Test case code file or files, like app.py

    PY
    import unittest
    import os
    
    class TestStringMethods(unittest.TestCase):
    
        def test_upper(self):
            test_str = os.getenv('TEST_STR')
            self.assertEqual('foo'.upper(), test_str)
    
        def test_isupper(self):
            self.assertTrue('FOO'.isupper())
            self.assertFalse('Foo'.isupper())
    
        def test_split(self):
            s = os.getenv('SPLIT_STR')
            #s = 'hello world'
            self.assertEqual(s.split(), ['hello', 'world'])
            # check that s.split fails when the separator is not a string
            with self.assertRaises(TypeError):
                s.split(2)
    
    if __name__ == '__main__':
        unittest.main()
  2. requirements.txt file
    if your python script use some specific libraries, you can create a requirements.txt file in your root folder, Testany will auto download these libraries in python execute environment.
    requirements.txt example

    TEXT
    requests

zip all the related files as one zip file, in this case the test case package file is python-test.zip

After you’ve successfully prepared the .zip file, you will be able to go to register your test case on Testany Platform. Please refer to <Managing Test Case> for the registration step-by-step guide.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.