Login

Snippets by simonbun

Snippet List

Forcing unit test runner to abort after failed test

Sometimes running a test suite can take a long time. This can get especially annoying when you see a failure or error, but have to wait for all the remaining tests to run before you can see the relevant stack traces. Pressing ctrl+c to interrupt the tests does not work; the KeyboardInterrupt exception does not get caught and only a stack trace irrelevant to your tests is produced. This behavior can be altered through overriding the testcase's `run` method and catching the exception yourself. Now you can stop the tests whenever you want to and still see what is wrong with your tests.

  • unit-test
Read More

RequestStack middleware

This is some very simple middleware that keeps track of the last 3 succesful requests for each visitor. This can be useful if you want to redirect the visitor to a previous path without relying on a hidden field in a form, or if you simply want to check if a visitor has recently visited a certain path. Note that this relies on the session framework and visitors actually accepting cookies. This can be easily modified to hold more requests if you have a need for it.

  • middleware
Read More

simonbun has posted 2 snippets.