Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

Commit 1203dc1

Browse files
committed
Fix the way tests run
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 adds the current directory as module search path and this 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.
1 parent 6d8d50b commit 1203dc1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+41
-34
lines changed

.circleci/unittest/linux/scripts/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ conda install -y -c "pytorch-${UPLOAD_CHANNEL}" ${CONDA_CHANNEL_FLAGS} pytorch c
1515

1616
printf "* Installing torchtext\n"
1717
git submodule update --init --recursive
18-
python setup.py develop
18+
python setup.py install
1919

2020
printf "* Installing parameterized\n"
2121
pip install parameterized

.circleci/unittest/linux/scripts/run_test.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@ eval "$(./conda/bin/conda shell.bash hook)"
66
conda activate ./env
77

88
python -m torch.utils.collect_env
9-
pytest --cov=torchtext --junitxml=test-results/junit.xml -v --durations 20 test
9+
10+
# Do not run pytest from the root directory of the repository.
11+
# The checked out code will be added to the Python module search path and
12+
# will shadow the development/instaled package.
13+
cd test
14+
pytest --cov=torchtext --junitxml=test-results/junit.xml -v --durations 20 torchtext_unittest

.circleci/unittest/windows/scripts/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ conda install -y -c "pytorch-${UPLOAD_CHANNEL}" ${CONDA_CHANNEL_FLAGS} pytorch c
2020

2121
printf "* Installing torchtext\n"
2222
git submodule update --init --recursive
23-
"$root_dir/packaging/vc_env_helper.bat" python setup.py develop
23+
"$root_dir/packaging/vc_env_helper.bat" python setup.py install
2424

2525
printf "* Installing parameterized\n"
2626
pip install parameterized

.circleci/unittest/windows/scripts/run_test.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@ eval "$(./conda/Scripts/conda.exe 'shell.bash' 'hook')"
66
conda activate ./env
77

88
python -m torch.utils.collect_env
9-
pytest --cov=torchtext --junitxml=test-results/junit.xml -v --durations 20 test
9+
10+
# Do not run pytest from the root directory of the repository.
11+
# The checked out code will be added to the Python module search path and
12+
# will shadow the development/instaled package.
13+
cd test
14+
pytest --cov=torchtext --junitxml=test-results/junit.xml -v --durations 20 torchtext_unittest

pytest.ini

Lines changed: 0 additions & 3 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)