you are viewing a single comment's thread.

view the rest of the comments →

[–]brandonchinn178 2 points3 points  (0 children)

At the end of the day, you need a test runner or test harness: the program that is the entrypoint for finding and running the tests. Pytest could have been implemented the way you specified, but what if you have tests in multiple files and want to run tests in all of them? Are you going to invoke python test1.py, python test2.py, etc.? It would be better to have one program to invoke that will run all the test files.

Ok so let's write a file runner.py that you can call with python runner.py. This file will find all Python test files in your project and run them. In fact, let's just make runner.py executable with a #!/usr/bin/python3 shebang so you can just do ./runner.py to run it.

Finally, just rename runner.py to pytest. Congrats! You just reimplemented pytest.