hatch icon indicating copy to clipboard operation
hatch copied to clipboard

Indicator to show the selected environment for hatch test

Open cdwilson opened this issue 1 year ago • 1 comments

In the testing tutorial, it says:

If no environment options are selected, the test command will only run tests in the first defined environment that either already exists or is compatible.

Would it be possible to add some additional output to hatch test -s that indicates the environment that hatch test will use? Maybe a * or something next to the selected environment in the "Envs" column?

┏━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓
┃ Name       ┃ Type    ┃ Envs                ┃ Dependencies                    ┃ Scripts     ┃
┡━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩
│ hatch-test │ virtual │ * hatch-test.py3.12 │ coverage-enable-subprocess==1.0 │ cov-combine │
│            │         │   hatch-test.py3.11 │ coverage[toml]~=7.4             │ cov-report  │
│            │         │   hatch-test.py3.10 │ pytest-mock~=3.12               │ run         │
│            │         │   hatch-test.py3.9  │ pytest-randomly~=3.15           │ run-cov     │
│            │         │   hatch-test.py3.8  │ pytest-rerunfailures~=14.0      │             │
│            │         │                     │ pytest-xdist[psutil]~=3.5       │             │
│            │         │                     │ pytest~=8.1                     │             │
└────────────┴─────────┴─────────────────────┴─────────────────────────────────┴─────────────┘

It would have been helpful for me when I was confused trying to understand which environment was being used when I ran hatch test.

cdwilson avatar Jul 17 '24 07:07 cdwilson

yeah, the selection process isn’t 100% trivial, as it prefers the default python to the newest Python, I think.

I use this nushell command which makes all paths of existing environments a link, so I can kinda see which one it is when I only run one:

def 'hatch env find' [search: string] {
  ^hatch env find $search | lines | each { |path|
    let exists = try { ls -D $path; true } catch { false }
    if $exists {
      $path | url encode | prepend 'file://' | str join '' | ansi link --text $path
    } else {
      $path
    }
  }
}

flying-sheep avatar Mar 12 '25 12:03 flying-sheep