How do i get the folder name from toxinidir (full path) variable? #2963
-
I am new to tox and currently implementing tox in a pipeline. We use pytest for testing the code and want to store the reports of the unit tests in a different folder than the source code. I have been trying to play around with {toxinidir} variable but it returns the full path of the directory and for the report path, i want to calculate the relative path from the folder in which tox.ini file is placed. I also tried to do tox -x or --override to override the set variables in the tox.ini file but doesn't look like i am using it correctly. I have attached a sample of the tox.ini file i am using.
Any help/pointers would be appreciated. :) TIA, |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 1 reply
-
What is the issue you experience when combining |
Beta Was this translation helpful? Give feedback.
-
For instance my toxinidir is: /codebuild/output/tmp/.builds/region/ABC_001 When i use toxinidir as per the example tox.ini file: So i want to extract the folder name ABC_001 from the path of toxinidir variable and then use it in the pytest command |
Beta Was this translation helpful? Give feedback.
-
You need to start with e.g. and untested You can easily try things out in your terminal... e.g. for me |
Beta Was this translation helpful? Give feedback.
-
Yes, that works but i still want to use the foldername also as the report-prefix: Already known facts: and I want to extract the directory name (ABC_001) from toxinidir full path and then use it as I am mainly struggling with how to calculate the reportfilename from toxinidir variable. |
Beta Was this translation helpful? Give feedback.
-
I think you could also wrap your command in a bashfile and there you can use
|
Beta Was this translation helpful? Give feedback.
-
I was referring to create a real bash file, and then executing it in the commands section. ie create a test.sh file, put all your manipulations in there, and then call it in the commands section.
|
Beta Was this translation helpful? Give feedback.
-
Thanks a lot @jugmac00 for the the help, it works indeed. But i was thinking of a more elegant solution to handle all this inside the tox.ini file itself. I have placed test.sh in a common directory rather than copying it to all the build directories for each python package we generate. Only downside of this solution is there is no one place where all config was stored as in (tox.ini) for one particular python package/source code and this is just a simple version but we will have to customise (test.sh) further for some edge cases. Would have been nice if all this could have been done in tox.ini. test.sh
tox.ini
Also, as i am invoking tox via my python script for each python package like:
is it also possible to somehow pass that information when calling tox.main() which can be consumed by the pytest command in tox.ini file? |
Beta Was this translation helpful? Give feedback.
I think you could also wrap your command in a bashfile and there you can use
basename
to get the directory name.