I have a Jupyter notebook that I plan to run repeatedly. It has functions in it, the structure of the code is this:
def construct_url(data):
...
return url
def scrape_url(url):
... # fetch url, extract data
return parsed_data
for i in mylist:
url = construct_url(i)
data = scrape_url(url)
... # use the data to do analysis
I'd like to write tests for construct_url and scrape_url. What's the most sensible way to do this?
Some approaches I've considered:
- Move the functions out into a utility file, and write tests for that utility file in some standard Python testing library. Possibly the best option, though it means that not all of the code is visible in the notebook.
- Write asserts within the notebook itself, using test data (adds noise to the notebook).
- Use specialised Jupyter testing to test the content of the cells (don't think this works, because the content of the cells is going to change).
Aucun commentaire:
Enregistrer un commentaire