wntrblm / nox

Flexible test automation for Python
https://nox.thea.codes
Apache License 2.0
1.28k stars 146 forks source link

Get session list in code #719

Open lhupfeldt opened 1 year ago

lhupfeldt commented 1 year ago

How would this feature be useful?

I would like to get the list of sessions from within a session in the noxfile. I use the session list to generate json (with further options) for integration with jenkins pipelines.

Describe the solution you'd like

Expose Manifest.list_all_sessions(self) -> Iterator[tuple[SessionRunner, bool]] as a function in the nox module.

Describe alternatives you've considered

I looked at the code, but it seems that it is not simple to get the list.

Anything else?

No response

henryiii commented 4 months ago

Nox supports json output for the session list for the last couple of releases. You can process with jq or Python. Is that fine? Sounds like exactly what you need.

lhupfeldt commented 3 months ago

This is exactly what i don't want. I don't want to invoke a new nox process from within a nox session. The same data available from the command line as json, should be available as a python dict or as Iterator[tuple[SessionRunner, bool]] or similar with a single function call within an existing nox process.

Walter-Gates-Bose commented 3 months ago

I would find this useful as well. I am trying to write a session that will create lock files with pip-tools and want one lock file per session. It would be useful to not have to call nox from within nox; I either have to install nox within that session or make sure nox can be found outside that session.

@henryiii, The nox --list-sessions --json output is constrained when nox.options.sessions is used to just those sessions in that list, that makes it potentially less useful for automation purposes than I think it was intended. I can get around it because I don't want to create a lock file for the session that creates lockfiles using nox -k "not lock" --list-session --json, but others might not.