Wednesday, May 19, 2021

Python Automation and Testing Modules

Selenium
-------- 

 

Installing chromedriver 

2. Copy binary to /usr/local/bin (or on any of your $PATH) 
"" 
list of downloads: 
https://chromedriver.storage.googleapis.com/index.html 

 

Quality Control 

--------------- 

 

`doctest` 

Performs tests on examples in docstings. This makes sure that the examples are align with the 
code. 

def average(values): 

    """Computes the arithmetic mean of a list of numbers. 

 

    >>> print(average([20, 30, 70])) 

    40.0 

    """ 

    return sum(values) / len(values) 

 

import doctest 

doctest.testmod()   # automatically validate the embedded test 

`unittest` 

Allows tests to be maintained on a separate file. 

import unittest 

 

class TestStatisticalFunctions(unittest.TestCase): 

 

    def test_average(self): 

        self.assertEqual(average([20, 30, 70]), 40.0) 

        self.assertEqual(round(average([1, 5, 7]), 1), 4.3) 

        with self.assertRaises(ZeroDivisionError): 

            average([]) 

        with self.assertRaises(TypeError): 

            average(20, 30, 70) 

 

unittest.main()  # Calling from the command line invokes all tests 

No comments:

Post a Comment