makepackage icon indicating copy to clipboard operation
makepackage copied to clipboard

Run tests after creating a package

Open nyggus opened this issue 3 years ago • 2 comments

Implement the following functionality: After creating a package, tests should be run, including pytest and doctest. If they all pass, it means that the package is created correctly and all the imports work fine.

nyggus avatar Sep 15 '22 11:09 nyggus

Hi, I just installed makepackage and it works well. Very easy. Nice work!

I just made a simple config class. Then I ran python form the terminal imported my ConfigDev and was able to use all its attributes.

I noticed this issue and looks like something I can help with.

I pip install pytest – which I didn’t know was a module

Then I ran pytest in terminal and I got this message below.

It seems in the tests folder there are scripts referring to the foo, bar, baz example that came pre-written with makepacakge. Is this something I should change as well? Maybe I’m supposed to make test functions that should execute with the import of my package “configwsh”? image

costa-rica avatar Sep 15 '22 13:09 costa-rica

Hi. Yes, the three functions—foo(), bar() and baz()—are included in the class. If you run pytest before changing anything, all the tests should pass.

However, when you make the first changes in the package, you should get rid of these functions. There are there only... only to be! And to serve as examples. So, let's assume you want to write a function do_funny_stuff(). You implement it in the module and remove the three above-mentioned functions. Then you have to

  • change the init.py file, to remove the import of these three functions;
  • change the test file, by removing the tests of these three functions and adding the test of do_funny_stuff(). After that, pytest will simply run your test, and not the tests included there before.

If you wonder why I included these functions there, I can explain that. They are simply needed there to make the package a working body. Otherwise, you could not even check if it works. After creating a package with makepackage and changing nothing, both pytest tests and doctest tests will pass (unless something went wrong during the package's creation process). So, if you change anything and the tests do not pass, this is due to your changes to the package, right? In my opinion, this helps in the first stage of development: you do not have to wonder if this is a problem of y our added code or of the package's code. But of course, this solution does not come without cost: you need to remove the three pre-implemented functions. But this can be done in a couple of minutes, that's all.

So, the point is that at the very beginning, you know the package works. Without those functions, you would not know that. Imagine the package does not have these functions and the corresponding tests; you have implemented your first function, added a test for it, and then run pytest — which fails. At least my first thought would be, hey, maybe it's not my function or my test, maybe the package is incorrectly created? And this would be a very valid point because manual creation of a package often leads to problems of various sorts, even if the function and its test are correct.

I am happy you're using makepackage. Don't hesitate to ask any questions here. I will check if the documentation explains this; perhaps you did not know how to proceed because the documentation does not explain that clearly enough. Thanks for the question!

nyggus avatar Sep 15 '22 13:09 nyggus