| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
The unit tests and the test data are bundled together in the package MDAnalyisTests. In order to run the tests, this package must be installed in addition to MDAnalysis.
The tests also rely on the pytest and numpy packages, and require both to run.
Install MDAnalysisTests via pip
pip install --upgrade MDAnalysisTests
or via conda
conda install -c conda-forge MDAnalysisTests
or download the tar file, unpack, and run python setup.py install.
Run the tests by invoking (--disable-pytest-warnings suppresses a large number of harmless warnings)
pytest --disable-pytest-warnings --pyargs MDAnalysisTests
(See Plugins for how to use the pytest-xdist plugin to run tests in parallel on a multicore machine.)
All tests should pass (i.e. no FAIL, ERROR); SKIPPED or XFAIL are ok. For anything that fails or gives an error ask on the user mailing list or raise an issue.
We are borrowing some of NumPy's testing frame work; thus, numpy must be installed for the tests to run at all.
It is recommended that you run the tests from the git source repository, which are located in the testsuite/MDAnalysisTests directory:
cd testsuite/MDAnalysisTests pytest --disable-pytest-warnings
Note: We use the --disable-pytest-warnings when the whole testsuite is running since we have a lot of false positives when we warn users about missing topology attributes. When running single tests or only single modules consider running the tests with warnings enabled. This allows you to see if you trigger any un-caught deprecation warnings or other warnings in libraries we use.
Running the tests serially can take some time, depending on the performance of your computer. (You can speed this up by running tests in parallel using pytest-xdist - explained in the plugin section)
To run specific tests just specify the path to the test file:
pytest path_to/MDAnalysisTests/analysis/test_align.py
Note: You have to replace path_to with the actual path to where the code is.
Specific test classes inside test files, and even specific test methods, can also be specified:
# Test the entire TestContactMatrix class pytest path_to/MDAnalysisTests/analysis/test_analysis.py::TestContactMatrix # Test only test_sparse in the TestContactMatrix class pytest path_to/MDAnalysisTests/analysis/test_analysis.py::TestContactMatrix::test_sparse
This is very useful when you add a new test and want to check if it passes.
Sometimes test failures in compiled functions wrapped in Cython can be obscured by a segfault or other memory error in the compiled layer. If you suspect this may be the case try re-running the tests using a protected memory environment, eg using Valgrind.
pytest-xdist - This can be used to run the tests in parallel.
pip install pytest-xdist pytest --disable-pytest-warnings --numprocesses 4
You can try increasing the number of processes to speed up the test run depending on you machine.
pytest-cov This can be used to generate the coverage report locally.
pip install pytest-cov pytest --cov=MDAnalysis
Note: You can use the --numprocesses flag with the above command too.
This will print the coverage statistic for every module in MDAnalysis at the end of a run. To get detailed line by
line statistics you can add the --cov-report=html flag. This will create a htmlcov folder (in the directory
you run the command from) and there will be an index.html file in this folder, open this file in your browser
and you will be able to see overall statistics and detailed line coverage for each file.
We use pylint for checking source code formatting. Install pylint with conda or pip.
Run the tests with our configuration with
pylint --rcfile=package/.pylintrc package/MDAnalysis pylint --rcfile=package/.pylintrc testsuite/MDAnalysisTests
This should finish without warnings or errors and show a message such as
------------------------------------------------------------------- Your code has been rated at 10.00/10
We also test that our documentation builds without problems. You will need to have the following packages installed:
cd package && python setup.py build_sphinx
Look at the generated html pages in build/sphinx/html/index.html.
The tests are in a separate package, together with any data files required for running the tests (see Issue 87 for details). Whenever you add a new feature to the code you should also add a test case (ideally, in the same git commit so that the code and the test case are treated as one unit).
Add a test for
The SciPy testing guidelines are a good howto for writing test cases.
The simulation data used in tests are all released under the same license as MDAnalysis or are in the Public Domain (such as PDBs from the Protein Databank). An incomplete list of sources:
The way we organized the unit tests changed between releases. The procedure for the current release is detailed at the very top of the page. The following list is for historical reference and in case you ever want to go back to a previous release.
| Back | FazBrowse Home | New Git URL |