With native tags, the templatetag is simply just a function you define which
means that testing the underlying functionality of your templatetag does not
require going to your browser. Just pass in the appropriate arguments and test the output.
Here is an example of unittesting a native tag which demonstrates how trivial it can be:
# tests.pyfromdjango.testimportTestCasefromnative_tagsimportfunction# Define or import your tags here@functiondefadder(x,y):returnx+yclassAdderTest(TestCase):deftest_adder(self):self.assertEqual(adder(1,1),2)
That is the full example above, but to add simple tests to a native function, you can use the
test attribute passing in the arguments and expected result of the function call.
Here is a shorter example that does the same thing as above: