Week 1 of the DevNet Grind – Python Script “unittest” and “Pytest” for testing scripts with scripts Hands on Lab!

pytest1

This will be in regards to Unit Testing, just grabbing lab screen snips for now

pytest2

pytest3

pytest4

This showing no result is correct because we don’t want a JSON value returned, so time to write some actual unittest for python!

pytest5

Note below the unittest is using data “from” other scripts in the same directory!

pytest6

pytest7

As seen below this script test has failed as indicated by the highlighted output:

pytest8

pytest9

pytest11

pytest12pytest13

pytest14

A new hopefully working test here:

pytest15

At first it fails, but then a “-m unittest” get its to work and check in OK!

pytest16

pytest17pytest18

In conclusion, there is a URL that should be well know for Python Script testing:

https://docs.python.org/3/library/unittest.html

I will work with that a bit more to understand, but not sure when I will circle back around to that, as I have so much labbing to catch up on here so I may point code / unit testing to this article.

Think I am done dumping posts for this AM, until next time šŸ™‚

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s