Repository navigation
Description
This issue is divided into 4 proposals. It is not easy to create 4 different issues without increasing the confusion because they are tightly coupled together. They all revolve around improving the documentation for using and running unit tests within this project; i.e. reducing the barrier for developers to commit quality code fast.
I can work out the details of the PR.
Proposal 1: Commit to 1 idiom to run tests
We currently suggest the following to run tests:
>>> import statsmodels.api as sm
>>> sm.test()
However, this is not how we run tests in travis.
Proposal: unify the 2 ways we document running tests into a single idiom, and document that as the way to run them. There are three main reasons to stick to pytest:
- the developer may not want to install
statsmodelsto run the tests. - CI is the most reliable source of truth about the outcome of the software, and we should mimic it as much as possible locally to speed up development
pytestgives more control e.g. over the output, and is way more used than callingX.test()within Python.
Specifically, I propose the following:
- make
pytestan optional dependency, like nose, to run tests. - change
test_notes.rstto describe how to run tests from beginning to end. I.e.
1. clone the source from GitHub
2. install the necessary dependencies using `pip install -r requirements-dev.txt` (or through anaconda)
3. compile the cython extensions using `python setup.py build_ext --inplace`
4. run the tests using `py.test -s --pyargs statsmodels`
Proposal 2: increase visibility of how to run tests
It should be very clear, for a new user or developer, how to run the tests. However, there is no mention of how to run unit tests in the README, contributing or install. From README to test_notes.rst it takes a minimum of 3 clicks to know what is the command to run the tests:
- README -> docs
- docs -> contribute
- contribute -> testing notes
(or, you know, check .travis.yml...)
Furthermore, I may not want to contribute or install statsmodels to run the tests.
Proposal: add a section to README pointing to the test notes page, or better, describing how to run a test. Specifically, after section Installing from source, add:
Running the tests
=================
This package is heavily tested. To run its tests locally:
1. clone the source from GitHub
2. install the necessary dependencies using `pip install -r requirements-dev.txt` (or through anaconda)
3. compile the cython extensions using `python setup.py build_ext --inplace`
4. run the tests using `py.test -s --pyargs statsmodels`
See more details on :ref:`testing`.
http://www.statsmodels.org/devel/dev/test_notes.html
(in this case, the section Running Test Suite in test_notes should be focused on how to run parts of tests, that python setup.py build_ext --inplace must be run after changes in cython, etc.).
Proposal 3: add a requirements-dev.txt
There is no reason for the list of dependencies to be presented to the developer as restructured text:
* `NumPy <http://www.scipy.org/>`__ >= 1.8
* `SciPy <http://www.scipy.org/>`__ >= 0.14
* `Pandas <http://pandas.pydata.org/>`__ >= 0.14
* `Patsy <https://patsy.readthedocs.io/en/latest/>`__ >= 0.3.0
* `Cython <http://cython.org/>`__ >= 0.24 is required to build the code from
github but not from a source distribution.
[...]
* `Nose <https://nose.readthedocs.org/en/latest>`__ is required to run
the test suite.
and force him to type them into pip or anaconda.
Proposal add a requirements-dev.txt that the developer can easly install with pip install -r requirements-dev.txt.
Proposal 4: suggest a workflow to contribute
The first section of test_notes describes that we strive to be test-driven. However, as it stands, it does not say how the developer achieves that within this project. The previous proposals focused on steps that make the development with unit testing faster and easier. With them in place, we can suggest one workflow to achieve test-driven development. For example
Suppose that you want to change `statsmodels.stats.Contrast` to have a function that changes the design matrix, `.change_design(new_design)`. This is an example of the process you could take to achieve this
1. **write the test**: in `statsmodels/stats/tests/test_contrast.py`, add to the class `TestContrast` the function `test_change_design`, testing that calling the function `change_design(Y)` changes the attribute `.design` to `Y`.
2. **run the test**: `py.test -s --pyargs statsmodels.stats.tests.test_contrast::TestContrast::test_change_design`. It should fail.
3. **change statsmodels**: in `statsmodels/stats/contrast.py`, add the function to `Contrast` and implement it.
4. **run the test again**
Once you are satisfied that the functionality exists and it is sufficiently tested, the testing part of your work is done. You can now continue the contribution (e.g. write documentation, etc.).
Activity
bashtage commentedon Feb 4, 2018
test()is left-over from early days when testing followed NumPy test discovery. I agree that this is unneeded now and likely confusing.josef-pkt commentedon Feb 4, 2018
.test()was always a user focused command, not for developers. E.g. I check often after installing some other packages (numpy, scipy, ...) whether the install is fine with xxx.test(). The advantage for users is that they never to have to think about commandline usage or what nosetests/pytest option to run.nosetests, or now pytest, with some path is much better for development, but will be less familiar to users.
2 and 4 are documentation issues where improvements are always helpful
3 is potentially still controversial. I haven't kept up with what the pip default options now are if a requirement file is specified. (does it still try to upgrade numpy and scipy?)
jbrockmendel commentedon Aug 10, 2018
Like so many other things that institutional inertia keeps unfixed, PytestTester is thoroughly inconsistent across the codebase.
Has it:
Doesn't:
Not even gonna bother checking the wretched hive of scum and villainy that is
sandboxMAINT: Add test runners
MAINT: Add test runners
MAINT: Add test runners
MAINT: Add test runners
MAINT: Add test runners
DOC: Update test running instructions