simple pytest example the exact import statement will depend on where you placed the calculator file relative to the test class in this case the two files are both in the same directory and so we can writefrom calculator import calculator we will now define testthe test should be pre-fixed with test_ for pytest to find them in fact pytest uses several conventions to find testswhich aresearch for test_py or *_test py files from those filescollect test itemstest_prefixed test functionstest_prefixed test methods inside test prefixed test classes (without an__init__methodnote that we keep test files and the files containing the code to be tested separateindeed in many cases they are kept in different directory structures this means that there is not chance of developers accidentally using tests in production code etc now we will add to the file function that defines test we will call the function test_add_oneit needs to start with test_ due to the above convention howeverwe have tried to make the rest of the function name descriptiveso that its clear what it is testing the function definition is given belowfrom calculator import calculator def test_add_one()calc calculator(calc set( calc add(assert calc total = the test function creates new instance of the calculator class and then calls several methods on itto set up the value to addthen the call to the add(method itself etc the final part of the test is the assertion the assert verifies that the behaviour of the calculator is as expected the pytest assert statement works out what is being tested and what it should do with the result--including adding information to be added to test run report it avoids the need to have to learn load of assertsomething type methods (unlike some other testing frameworksnote that test without an assertion is not testi it does not test anything many ides provide direct support for testing frameworks including pycharm for examplepycharm will now detect that you have written function with an assert statement in it and add run test icon to the grey area to the left of the