statsmodels / statsmodels

Statsmodels: statistical modeling and econometrics in Python
http://www.statsmodels.org/devel/
BSD 3-Clause "New" or "Revised" License
9.96k stars 2.86k forks source link

FAQ-D: How do I run the unit tests during development? #2232

Closed josef-pkt closed 5 years ago

josef-pkt commented 9 years ago

nose has a nice feature to run only selected tests which is very useful during development. see examples below.

Running the entire set of unit tests in statsmodels is relatively slow, too slow to be convenient during development. We have continuous integration testing through Travis-CI, but it takes 15 minutes or more to get a response.

The easiest and fastest way during development is to run the unit tests that are directly affected by new code or changes to the code.

For example, I have an open shell (operating system command window) where I just run the nosetests script with the relevant path to the unit tests. I'm using a temporary working directory, but any directory is fine as long as it is not in the statsmodels source tree.

Here are some examples from my current session:

running all tests in a module or directory including subdirectories

nosetests "E:\my_checkout_path\statsmodels\statsmodels\tsa\statespace\tests\test_sarimax.py"
nosetests "E:\my_checkout_path\statsmodels\statsmodels\tsa\statespace\tests"
nosetests "E:\my_checkout_path\statsmodels\statsmodels\tsa"

nosetests "E:\my_checkout_path\statsmodels\statsmodels\regression\tests"
nosetests "E:\my_checkout_path\statsmodels\statsmodels\regression\tests\test_robustcov.py"
nosetests "E:\my_checkout_path\statsmodels\statsmodels\discrete\tests\test_sandwich_cov.py"

running specific tests which is useful if there are slow tests in the same module, or the module has many tests:

nosetests --pdb "E:\my_checkout_path\statsmodels\statsmodels\discrete\tests\test_sandwich_cov.py:TestPoissonCluFit"

running modules or parts of statsmodels specified by python path:

nosetests statsmodels.tools.tests.test_numdiff

The nosestest options that I use most often are --pdb and --pdb-failures which drop into the debugger when, respectively, an error or a failure occurs.

I'm on Windows and have backslash as path separator, and can directly copy the filename or directory name from windows explorer into the shell with nosetest. This works fast and is very convenient.

Running a subset of tests in the current Python version is enough for development, but it does not do enough testing. However, we have Travis-CI and other machines that run all the unit tests with different versions of Python and our dependencies. This will catch most "left-over" bugs (if they have test coverage) and in most cases there are only a few version or precision problems to fix.

jbrockmendel commented 5 years ago

Closeable? Since we're no longer using nose, this is out of date

bashtage commented 5 years ago

No longer correct or relevant.