Skip to content
Peter Kessen edited this page Sep 16, 2015 · 12 revisions

Running the Tests

The usual way to run the tests is with nose. Just type nosetests in the beets repository.

To run the tests for multiple Python versions, compile the docs, and check style, use tox. Just type tox or use something like tox -e py27 to test a specific configuration. detox makes this go faster.

Other ways to run the tests:

  • python setup.py test (although log messages are not silenced)
  • cd test ; python testall.py (ditto)
  • py.test

You can also see the latest test results on Travis.

Test Dependencies

The tests have a few more dependencies than beets itself. (The additional dependencies consist of testing utilities and dependencies of non-default plugins exercised by the test suite.) The dependencies are listed as tests_require in setup.py.

Writing Tests

Writing tests is done by adding or modifying files in folder test. Take a look at https://github.com/sampsyo/beets/blob/master/test/test_template.py#L224 to get a basic view on how tests are written.

Basics

  • Your file should contain a class derived from unittest.TestCase
  • Each method in this class which name starts with the letters test will be executed to test functionality
  • Errors are raised with these methods:
    • self.assertEqual
    • self.assertTrue
    • self.assertFalse
    • self.assertRaises
  • For detaild information see Python unittest

Running single tests

While you are writing you may want to test your new test. Assuming the test file you are working on is test_template.py, you can run this test by typing nosetests test.test_template in a shell in the root directory of your beets repository

Red Flags

nosetests --with-coverage: Coverage is pretty low still -- see the current status on Codecov.

python -3 testall.py: Raises a few warnings, and a lot of warnings for Mutagen. Right now, the warnings are: buffer has been replaced with memoryview in py3k, and we use some integer division.

Use unicode-nazi. This tool finds lots of places where we're sloppy about Unicode strings. Try running python -m unicodenazi beet version or putting import unicodenazi at the top of testall.py.

The pytest-random plugin makes it easy to randomize the order of tests. py.test test --random will occasionally turn up failing tests that reveal ordering dependencies—which are bad news!

Clone this wiki locally