[test][python] allow to overwrite the interpreter for python test command
When using dune_python_add_test the SCRIPT is executed by default with the detected python interpreter. The optional INTERPRETER parameter allows to overwrite this setting, e.g. to pass additional command line arguments or to execute the tests using pytest.
Merge request reports
Activity
@dominic is this sufficient for your use case of
pytest
?Pytest is either invoked as
python -m pytest
(preferred) or aspy.test
. With the current situation, I would need to pass-m pytest
toSCRIPT
to get that, which sounds weird. I do also need this custom interpreter parameter though.Edited by Dominic KempfI though you call something like
SCRIPT foo.py INTERPRETER pytest
but I never used pytest, so apparently have misunderstood something here. Looking at your text above, I would have though, that you now call
SCRIPT foo.py INTERPRETER ${Python3_EXECUTABLE} -m pytest
Perhaps we have to collect a list of the different use cases, but the old state was broken with harder to detect errors than the explicit message we have now.
I wanted to make the suggestion to add a
MODULE
argument to the python test. I think that is preferable since this make this apython
test and not a catch all. So one would writedune_python_add_test(MODULE pytest foo.py)
which would translate toPython3_Interpreter -m pytest foo.py
) Could also bedune_python_add_test(MODULE pytest SCRIPT foo.py)
My main point is that I would like to get ${Python3_EXECUTABLE} out of downstream modules.
Edited by Andreas Dedner@andreas.dedner 's proposal is okay for me, as long as the
INTERPRETER
argument of this MR is also present, because I actually useDUNE_PYTHON_VIRTUALENV_INTERPRETER
and notPython3_EXECUTABLE
.If @dominic really wants to use a different interpreter throughout the whole project I see three options:
- replace the Python3_EXECUTABLE in the main CMakeLists.txt
- set an INTERPRETER for all dune_python_add_test calls
- add an additional cmake flag to change the behaviour and prefer DUNE_PYTHON_VIRTUALENV_INTERPRETER over Python3_EXECUTABLE
Perhaps (3) should be the default, if someone is working with a virtual env?!
The whole point of having a virtual environment is that
DUNE_PYTHON_VIRTUALENV_INTERPRETER != Python3_EXECUTABLE
- they are different. Also bear in mind, that I am not talking about users whose Python environment is actually a virtual env,DUNE_PYTHON_VIRTUALENV_INTERPRETER
refers to the virtual env that is automatically set up by the Dune build system (upon request). Why not just provide theINTERPRETER
argument fordune_python_add_test
- it defaults toPython3_EXECUTABLE
and your use case is untouched.You have a similar "security issue" in all test suites. If you write
subprocess.call("rm -rf *", shell=True)
into a Python test you have the same result. Running tests will always involve a certain level of trust. The important part is thatroot
access is protected - which is not an issue here.OK. So @andreas.dedner would you add the module option?
Regarding security, I agree with @dominic... it is not about not being able to do such things, but we should not encourage people to use the command for arbitrary operations.
I can finish this if you want (provide
INTERPRETER
andMODULE
parameters).Edited by Dominic Kempf
mentioned in commit fae77c75