Skip to content

Unify how we suggest running tests and decrease barrier to run them. #4245

Closed

Description

@jorgecarleitao

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:

  1. the developer may not want to install statsmodels to run the tests.
  2. 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
  3. pytest gives more control e.g. over the output, and is way more used than calling X.test() within Python.

Specifically, I propose the following:

  1. make pytest an optional dependency, like nose, to run tests.
  2. change test_notes.rst to 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:

(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

  1. bashtage commented on Feb 4, 2018

    @bashtage
    Member
    1. test() is left-over from early days when testing followed NumPy test discovery. I agree that this is unneeded now and likely confusing.
    2. Sure, why not.
    3. This is OK, but why not just requirements.txt, which isn't present. Given there are only two additional requirements for dev beyond what is needed to run (Cython and pytest), and both are easily installable from pypi for any common platform, why not KISS.
    4. Like 2, why not. I think there is a section of the notes on contributing. This could probably be improved.
  2. josef-pkt commented on Feb 4, 2018

    @josef-pkt
    Member
    1. for me .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?)

  3. jbrockmendel commented on Aug 10, 2018

    @jbrockmendel
    Contributor

    Like so many other things that institutional inertia keeps unfixed, PytestTester is thoroughly inconsistent across the codebase.

    Has it:

    base
    discrete
    emplike
    formula
    genmod
    graphics
    iolib
    miscmodels
    nonparametric
    regression
    robust
    stats
    tsa
    tsa.vector_ar
    tsa.statespace
    tsa.regime_switching
    

    Doesn't:

    compat
    datasets
    distributions
    duration
    genmod.families
    imputation
    (interface)
    multivariate
    multivariate.factor_rotation
    (resampling)
    tsa.kalmanf
    tsa.interp
    tsa.filters
    tsa.base
    tools
    

    Not even gonna bother checking the wretched hive of scum and villainy that is sandbox

  4. added a commit that references this issue on May 8, 2019
  5. self-assigned this
    on Dec 5, 2019
  6. added a commit that references this issue on Dec 5, 2019
    24d6737
  7. added this to the 0.11 milestone on Dec 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions