Skip to content

Commit

Permalink
[test] Let pytest-rerunfailures pytest-xdist to be hard dependences (#…
Browse files Browse the repository at this point in the history
…1187)

* [test] make pytest-rerunfailures pytest-xdist hard-dep

* [skip ci] enforce code format

* remove misc/empty_pytest.py

Co-authored-by: Taichi Gardener <taichigardener@gmail.com>
  • Loading branch information
archibate and taichi-gardener authored Jun 9, 2020
1 parent a8911f1 commit 4dcc638
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 30 deletions.
5 changes: 3 additions & 2 deletions docs/dev_install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ Installing Depedencies

.. code-block:: bash
python3 -m pip install --user setuptools astpretty astor pytest opencv-python pybind11
python3 -m pip install --user Pillow numpy scipy GitPython yapf colorama psutil autograd
python3 -m pip install --user setuptools astpretty astor pybind11 opencv-python
python3 -m pip install --user pytest pytest-rerunfailures pytest-xdist yapf Pillow
python3 -m pip install --user numpy scipy GitPython colorama psutil autograd
* (If on Ubuntu) Execute ``sudo apt install libtinfo-dev clang-8``. (``clang-7`` should work as well).

Expand Down
2 changes: 0 additions & 2 deletions misc/empty_pytest.py

This file was deleted.

39 changes: 13 additions & 26 deletions python/taichi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,35 +656,22 @@ def _test_python(args):
if args.verbose:
pytest_args += ['-s', '-v']
if args.rerun:
if int(
pytest.main([
os.path.join(root_dir, 'misc/empty_pytest.py'),
'--reruns', '2', '-q'
])) != 0:
sys.exit(
"Plugin pytest-rerunfailures is not available for Pytest!")
pytest_args += ['--reruns', args.rerun]
# TODO: configure the parallel test runner in setup.py
# follow https://docs.pytest.org/en/latest/example/simple.html#dynamically-adding-command-line-options
if int(
pytest.main([
os.path.join(root_dir, 'misc/empty_pytest.py'), '-n1', '-q'
])) == 0: # test if pytest has xdist or not
try:
from multiprocessing import cpu_count
threads = min(8,
cpu_count()) # To prevent running out of memory
except NotImplementedError:
threads = 2

try:
from multiprocessing import cpu_count
threads = min(8, cpu_count()) # To prevent running out of memory
except NotImplementedError:
threads = 2

if not os.environ.get('TI_DEVICE_MEMORY_GB'):
os.environ['TI_DEVICE_MEMORY_GB'] = '0.5' # Discussion: #769

env_threads = os.environ.get('TI_TEST_THREADS', '')
threads = args.threads or env_threads or threads
print(f'Starting {threads} testing thread(s)...')
if int(threads) > 1:
pytest_args += ['-n', str(threads)]
else:
print("[Warning] Plugin pytest-xdist is not available for Pytest!")
env_threads = os.environ.get('TI_TEST_THREADS', '')
threads = args.threads or env_threads or threads
print(f'Starting {threads} testing thread(s)...')
if int(threads) > 1:
pytest_args += ['-n', str(threads)]
return int(pytest.main(pytest_args))

@staticmethod
Expand Down

0 comments on commit 4dcc638

Please sign in to comment.