Packages !

Code organization is an important aspect of software development. Making program packages is a great way to organize your code and make your code accessible to share with others. Once your code is in a package you can import the package like NumPy and Random and use all the functions in the package. This cleans up the code you would have to write and lets you reuse code/functions you have already created easily. To start you should create a folder which will serve as your package and place your code inside of it. Then you should create a new file called setup.py and place the following code in it:

This code will set up the package for you and if you intend to upload the package to the Python Package Index (PyPi), the name you set would have to be unique. The final step to be able to import the code anywhere you need to use the "pip install -e ." command in the folder containing the setup.py. This will install the package into your python site packages folder. By adding an "init.py" file you can change the way you can import the functions from the python modules of your package. If done correctly, you can decrease the amount of imports you have to do for a package and import all the functions using just one import statement.

Testing in Pytest !

Writing code is important but making sure it does what you think it does is even more important. Thus, creating test cases to evaluate if your functions return what you think they should is essential. One way to do this is by creating assert statements. However, this is not as efficient as making a test suite that tests all your functions and makes sure they don't throw any exceptions. To do this you can install a testing framework called pytest using "pip install -U pytest-cov". Then create a folder called with test_name and inside create a python file starting with test_name.py. Inside this test_name.py folder you can add functions to run tests on the functions you have written in another file or package, but make sure to import them first. Then to run, you can just call "pytest" in the testing directory and it will run all the tests and let you know which have passed/failed.