Skip to main content

Nose plugin to randomly order tests and control random.seed.

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

https://img.shields.io/travis/adamchainz/nose-randomly.svg https://img.shields.io/pypi/v/nose-randomly.svg

Nose plugin to randomly order tests and control random.seed.

Features

All of these features are on by default but can be disabled with flags.

  • Randomly shuffles the submodules, TestCase classes + test functions when loading a module of tests.

  • Randomly shuffles the test functions inside a TestCase when loading it.

  • Resets random.seed() at the start of every test case and test to a fixed number - this defaults to time.time() from the start of your test run, but you can pass in --random-seed to repeat a randomness-induced failure.

  • If factory boy is installed, its random state is reset at the start of every test. This allows for repeatable use of its random ‘fuzzy’ features.

About

Randomness in testing can be quite powerful to discover hidden flaws in the tests themselves, as well as giving a little more coverage to your system.

By randomly ordering the tests, the risk of surprising inter-test dependencies is reduced - a technique used in many places, for example Google’s C++ test runner googletest.

By resetting the random seed to a repeatable number for each test, tests can create data based on random numbers and yet remain repeatable, for example factory boy’s fuzzy values. This is good for ensuring that tests specify the data they need and that the tested system is not affected by any data that is filled in randomly due to not being specified.

Usage

Install from pip with:

pip install nose-randomly

Nose will automatically find the plugin.

To activate it on your test run, use the --with-randomly flag, for example:

nosetests -v --with-randomly

The output will start with an extra line that tells you the random seed that is being used:

Using --randomly-seed=1234
test_D (abcd_tests.Tests) ... ok
...

If the tests then fail due to ordering or randomly created data, you can then restart them with that seed:

nosetests -v --with-randomly --randomly-seed=1234

You can disable behaviours you don’t like with the following flags:

  • --randomly-dont-shuffle-modules - turn off the shuffling of the contents of modules

  • --randomly-dont-shuffle-cases - turn off the shuffling of test functions inside TestCase classes

  • --randomly-dont-reset-seed - turn off the reset of random.seed() at the start of every test

Background

nose has an unmerged pull request from 2009 to add random ordering functionality. This is available in plugin format in the nose-randomize package. It works quite well but I found that since it replaces all of the test loading machinery inside nose, it can interact badly with other plugins. This plugin was developed as a thinner layer to achieve the same thing, plus the random seed restting which was not available before.

History

1.1.0 (2015-08-27)

  • Reset the random seed at the start of nose test contexts (TestCases etc.) too

  • Slight performance improvement by always using random.setstate() for reseeding

1.0.0 (2015-07-23)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nose-randomly-1.1.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

nose_randomly-1.1.0-py2.py3-none-any.whl (7.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file nose-randomly-1.1.0.tar.gz.

File metadata

File hashes

Hashes for nose-randomly-1.1.0.tar.gz
Algorithm Hash digest
SHA256 2991a275d581b4e94031949bd7b2a0cd6580ee2eba0f4ba5bf5a09694fcee16c
MD5 1cbcc8da11499ed2c1142c0fb9c950f9
BLAKE2b-256 a984f55ffb86823d1e860f7941ff337574d954af020f673648ce6f4166767f4e

See more details on using hashes here.

File details

Details for the file nose_randomly-1.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for nose_randomly-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 49ff3c87f7d2d12174e9024dd1a5f427c071a412ac2cd376f1ef20996f13cd50
MD5 331ef3dfe2d30cbe616121a51b777b16
BLAKE2b-256 da1092003b5d960e117b2758fa29ec064f75c9892dfe7344f36a9405b74f0fe9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page