Monday, November 30, 2020

Python nose introduction



Nose’s tagline is “nose extends unittest to make testing easier”.

It’s is a fairly well known python unit test framework, and can run doctests, unittests, and “no boilerplate” tests.


It is a good candidate for a go-to test framework.


a smart developer should get familiar doctest, unittest, pytest, and nose. Then decide if one of those makes the most sense for them, or if they want to keep looking for features only found in other frameworks.



Nose fixtures

Nose extends the unittest fixture model of setup/teardown.


We can add specific code to run:


at the beginning and end of a module of test code (setup_module/teardown_module)

To get this to work, you just have to use the right naming rules.

at the beginning and end of a class of test methods (setup_class/teardown_class)

To get this to work, you have to use the right naming rules, and include the ‘@classmethod’ decorator.


before and after a test function call (setup_function/teardown_function)

You can use any name. You have to apply them with the ‘@with_setup’ decorator imported from nose.

You can also use direct assignment, which I’ll show in the example.


before and after a test method call (setup/teardown)

To get this to work, you have to use the right name.




References:

https://pythontesting.net/framework/nose/nose-introduction/


No comments:

Post a Comment