text
text copied to clipboard
Fix the way tests are executed
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
- introduces
test/torchtext_unittestdirectory and moves all the test scripts and assets there. - changes
python setup.py developtopython setup.py installin CI job - run test with
(cd test && pytest torchtext_unittest)so that repository root is not in Python module search path. - Change relative import (
from ..common import ...) in test module to absolute import (from torchtext_unittest.common import ...) - deletes
pytest.ini, which hard-coded test path.