Tuesday 12 May 2020

Parametrize pytest with custom class

Some times while using pytest we may end up in situation where we would like to pass a class object for assertion.
In some of situations i have come across , i used the same principal for invoking custom functions inside a module.

Below example simplify the process of passing a parameter to a pytest. This object could have n number of properties a savior when you have more then 7 parameters passed to the pytest function.


The below test code will generate 10 tests and pass random values to the class object.

Later inside pytest the passed values will be asserted.


1  Create a test class


2.  Create a list to hold random generated objects and set values of each property with a random values from a list.


3. Create a pytest with marker parametrize and pass the object list .


4. Run the test . You will notice that 10 tests are generated each is passed .
command to run the pytest is  pytest scriptname




No comments:

Post a Comment

Apache Beam Learning In Java Tutorials

 Wow  https://youtu.be/9kGETU63rkc