Skip to main content

Posts

Showing posts with the label pytest

Things I Learned: Pytest and Python git Installs on Windows

 All of the Datasette plugins and enrichments contain this development instruction towards the bottom of their documentation page: Now install the dependencies and test dependencies: pip install -e '.[test]' However, on windows, the above pip install line does not work. It returns an error message: ERROR: '.[test]' Note that the single quotes are still in the message. That is in fact the issue. This command: pip install -e .[test] Does work on Windows. I've updated the documentation on the datasette-enrichments-gmap-geocode package to reflect this.

Today I Learned: pytest output

 Getting pytest to display output, even if the test case passes; sorting tuples by datetime Frequently, I find myself needing to watch print statements during development as pytest calls new methods. Today I learned how to force passing tests to write to the screen. The -rP option is the answer to that. I'm constantly impressed with how much pytest just already has implemented. Along the vein of 'wow, it just works', I was surprised to find how easy it was to sort tuples by date . On a side note, the StackOverflow question linked to in the previous sentence closed as a duplicate, and I don't think it should have been. I mean sure, there was a more general question that could be construed to be the answer if you already knew lots of Python, but that's kind of beside the point I think. If I knew enough python to make the construction, I probably wouldn't have asked the question . I mean I didn't ask that actual question, but you get the idea.

Why testing code rocks

 Why using pytest (or another framework) to test code routinely (as in every time code is added) saves bogs worth of time for developers.  I've found myself running away with adding new features to the reverse beacon network ( RBN )  mapping project over the last few days. It's been a lot of fun, and now there are prototype maps —for example —that show ionoshperic skip. It's been a LOT of fun, but I haven't been augmenting my documentation or testing for the project. So, this morning, I earnestly wrote myself a note to read back up on the importance of testing , then I  was slammed from my lofty testing heights back to the alley of  'banging out code' by inspiration for a shiny new feature , and I was off. Fortunately, the note in my journal acted as a positive reinforcment. As I started to write the new feature (animating maps via timestamps in Google Earth), I also popped open an existing pytest file , saved it under a new name, and started writing tests fo...

Things I Learned: Using pytest to check stdout from python methods

 So, adding automated remote station location updates to the code that tracks the Reverse Beacon Network spots of the KD0FNR Rockmite has become a bit of an oddysey , but here's more cool stuff: The output python script new_key_cat.py is supposed to present only lines of output (to stdout) that do not contain keys that already exist in rm_rnb_history_pres.csv. Tests are being built for the script using pytest. pytest mutes stdin because the tests are intended to be automated rather than interactive. This makes sense to me, so I'm changing the method in the script that handles input to look for a file name argument, and if it doesn't have one to use stdin. The second issue though was how to write an automated test case that looks at stdout. It turns out pytest has that covered. It's all written up at https://docs.pytest.org/en/7.1.x/how-to/capture-stdout-stderr.html And here's the pertinent code example from that page: def test_myoutput(capsys): # or use "capf...