You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_set_backend.py 741 B

3 years ago
12345678910111213141516171819202122
  1. import os
  2. import pytest
  3. from fastNLP.envs.set_backend import dump_fastnlp_backend
  4. from tests.helpers.utils import Capturing
  5. from fastNLP.envs.distributed import rank_zero_rm
  6. def test_dump_fastnlp_envs():
  7. filepath = None
  8. try:
  9. if 'CONDA_DEFAULT_ENV' in os.environ:
  10. with Capturing() as output:
  11. dump_fastnlp_backend(backend="torch")
  12. filepath = os.path.join(os.path.expanduser('~'), '.fastNLP', 'envs', os.environ['CONDA_DEFAULT_ENV']+'.json')
  13. assert filepath in output[0]
  14. assert os.path.exists(filepath)
  15. else:
  16. with pytest.raises(RuntimeError):
  17. dump_fastnlp_backend(backend="torch")
  18. finally:
  19. rank_zero_rm(filepath)