Error running Pytest

I have performed a ‘git pull’ today 27-08-2018 and for the fun off it I thought I would run ‘pytest tests’. However this fails with an import error for module ‘cv2’. I know on mac OS X 10.11.06 there is an issue with ‘opencsv’ see

My version of ‘opencsv’ is 3.3.1 which imports without error from python at a terminal. However when I run ‘pytest tests’ I get this error.

ImportError while importing test module ‘/Users/mac/FASTAI/fastai/tests/’.
Hint: make sure your test modules/packages have valid Python names.
tests/ in
import cv2,torch
E ModuleNotFoundError: No module named ‘cv2’

Note there should be 2 underscores either side of the init in tests/ but get lost in the posting of this message.

repeated for other test modules

  • test_dataset
  • test_layer_optimizer
  • test_lsuv_initialize
  • test_samplers
  • test_structured
  • test_transform

However the code in seems to be a fix for ubuntu 16.04. Also ‘cv2’ is only used in 2 modules

  • cv2 :: which imports it again
  • :: which relies on the ‘__ init’ import from '

I have raised an issue on github and then noted issue about testfixtures which I added to my cpu environment which did not remove the error.

Also I think it is an issue not just for cv2 but for other modules as well. It may be in my use of pytest. However I am following instructions on the github page.

I have solved this issue by:

  • running command pytest tests from a terminal in the fastai directory
  • delete / rename tests/ file
  • set PYTHONPATH=../fastai to allow the tests to find fast module
  • added the equivalent of sys.path for fastai-cpu to PYTHONPATH
  • export PYTHONPATH=../fastai:/Users/mac/anaconda3/envs/fastai-cpu/lib/
  • 69 tests passed a one was skipped
  • I was able to reinstate the file and the tests passed, one skipped