hi-ml icon indicating copy to clipboard operation
hi-ml copied to clipboard

Simplify test discovery in VSCode

Open ant0nsc opened this issue 3 years ago • 1 comments

When opening the repository in VSCode and starting test discovery, it will break with the first attempt to import from health_ml. Similarly, running pytest in either of the package folders will break at the same place.

What should work:

  • Running pytest on the commandline at repository root should run all tests in the 3 core folders correctly
  • Running pytest on the commandline in hi-ml, hi-ml-azure and histo should run tests in the respective folder
  • Running test discovery in VSCode should pick up at least the tests in hi-ml and hi-ml-azure

Possible solutions:

  1. Require everyone to run pip install -e . in the hi-ml and hi-ml-azure folders before doing any work. This must be done before doing any work on the repository. Downside: Repo is not fully workable without this manual step, and there are chances people forget to do it.
  2. Modify VSCode settings such that PYTHONPATH is modified before running pytest.
    • Problem: Did not get that to work, example below
    • Downside: This will not help on the commandline.
  3. Modify conftest.py to add the required source folders to sys.path.
    • Downside: This will then also run in the cloud builds. There, we do NOT want to use hi-ml from source because we install it via a wheel into site-packages. Could disable the path hacking via an environment variable.
  4. Modify pytest.ini to contain the pythonpath field, see doc.
    • Problem: I did not get that to work at all.
    • Downside: Again, this should not be run in cloud builds because of the use of wheels.

For modifying VSCode to set PYTHONPATH when running pytest, I tried this in settings.json:

"terminal.integrated.env.windows": {
        "PYTHONPATH":"${workspaceFolder}/hi-ml/src:${workspaceFolder}/hi-ml-azure/src"
    },
    "terminal.integrated.env.linux": {
        "PYTHONPATH":"${workspaceFolder}/hi-ml/src:${workspaceFolder}/hi-ml-azure/src"
    }

This could be tackled together with #192

ant0nsc avatar Feb 28 '22 10:02 ant0nsc

Just to make sure, does this assume that VS Code's interpreter is pointing to a conda environment created with environment.yml?

fepegar avatar Feb 28 '22 10:02 fepegar