UCLH-Foundry / PIXL

PIXL Image eXtraction Laboratory
Apache License 2.0
8 stars 0 forks source link

Fix `pixl check-env` tests #410

Open milanmlft opened 1 month ago

milanmlft commented 1 month ago

Definition of Done / Acceptance Criteria

The cli/tests/test_check_env.py tests are updated to correctly test the behaviour of pixl check-env.

Testing

Should update cli/tests/test_check_env.py

Suggested test cases:

  1. check_env(error=True) should pass without errors
  2. check_env(error=True) should return an error when a NONEXISTENT_VARIABLE envvar is set in the sample file
  3. check_env(error=False) should not return an error when a NONEXISTENT_VARIABLE envvar is set in the sample file (might be overkill)

Documentation

No response

Dependencies

No response

Details and Comments

The tests in test_check_env.py are currently passing because of the wrong reasons:

  1. test_check_env() passes because it's calling check_env with default options, so error = False and so will never return a non-zero exit code
  2. test_check_env_fails() passes because it's calling runner.invoke() in a faulty way. It also has error=False so the non-zero exit code doesn't actually come from check_env

To reproduce, modifying test_check_env() to the following still passes (but shouldn't!):

def test_check_env(tmp_path):
    """
    Test that the check_env command runs without error.
    - check_env works
    - current test env file matches the sample env file
    """
    tmp_sample_env_file = tmp_path / ".env.sample"
    tmp_sample_env_file.write_text("NONEXISTENT_VARIABLE=")

    runner = CliRunner()
    result = runner.invoke(check_env, ["--sample-env-file", tmp_sample_env_file])

    assert result.exit_code == 0