text icon indicating copy to clipboard operation
text copied to clipboard

Fix the way tests are executed

Open mthrok opened this issue 4 years ago • 0 comments

Currently torchtext runs tests by pytest test. This is fine for development but one cannot run unit test on installed package in this manner because running test from the root directory adds the current directory as module search path and the checked out code directory will shadow the installed package. Similarly if you do (cd test && pytest .), this does not work either because pytest will figure out where the test module root starts and add the repository root to python module search path.

When running test on CI, it is more desirable to install the package and run tests because it can catch a bug related to packaging. Such as zip_safe=False issue. (this cannot be caught with the current configuration)

To resolve this issue, this PR

  1. introduces test/torchtext_unittest directory and moves all the test scripts and assets there.
  2. changes python setup.py develop to python setup.py install in CI job
  3. run test with (cd test && pytest torchtext_unittest) so that repository root is not in Python module search path.
  4. Change relative import (from ..common import ...) in test module to absolute import (from torchtext_unittest.common import ...)
  5. deletes pytest.ini, which hard-coded test path.

mthrok avatar Mar 01 '21 22:03 mthrok