pytest: How to get a list of all failed tests at the end of the session? (and while using xdist)

Run pytest with -rf to get it to print a list of failed tests at the end. From py.test –help: -r chars show extra test summary info as specified by chars (f)ailed, (E)error, (s)skipped, (x)failed, (X)passed, (p)passed, (P)passed with output, (a)all except pP. Warnings are displayed at all times except when –disable-warnings is set Here’s … Read more

Jest unit test for a debounce function

Actually, you don’t need to use Sinon to test debounces. Jest can mock all timers in JavaScript code. Check out following code (it’s TypeScript, but you can easily translate it to JavaScript): import * as _ from ‘lodash’; // Tell Jest to mock all timeout functions jest.useFakeTimers(); describe(‘debounce’, () => { let func: jest.Mock; let … Read more

How do you change the behaviour of a mocked import in Jest?

After you’ve mocked the module and replaced the methodToMock with a spy, you need to import it. Then, at each test, you can change the behaviour of methodToMock by calling the mockImplementation spy method. jest.mock(‘the-package-to-mock’, () => ({ methodToMock: jest.fn() })) import { methodToMock } from ‘the-package-to-mock’ it(‘Test A’, () => { methodToMock.mockImplementation(() => ‘Value … Read more

How to detect that you’re in a test environment (check / determine if tests are being run)

Put this in your settings.py: import sys TESTING = len(sys.argv) > 1 and sys.argv[1] == ‘test’ This tests whether the second commandline argument (after ./manage.py) was test. Then you can access this variable from other modules, like so: from django.conf import settings if settings.TESTING: … There are good reasons to do this: suppose you’re accessing … Read more

Adding NUnit to the options for ASP.NET MVC test framework

After a bunch of research and experimentation, I’ve found the answer. For the record, the current release of nUnit 2.5 Alpha does not seem to contain templates for test projects in Visual Studio 2008. I followed the directions here which describe how to create your own project templates and then add appropriate registry entries that … Read more