-1

In terminal, I set the www site and path to create a report for my tests.

I set: MY_URL=mysite:myport REPORTPA=./mypath/mysecondfolder/ pytest -s testFile.py --html=REPORTPA/report.html

I should save report.html, I try a solution like:

$REPORTPA/report.html or %REPORTPA/report.html

and it's not using good. How I can use my variable?

karp102
  • 55
  • 8
  • 1
    See [here](https://stackoverflow.com/questions/30180187/setting-an-environment-variable-on-same-line-as-program-execution-is-different-t/30180842#30180842) for setting bash shell and environment vars. – progmatico Aug 26 '19 at 13:16
  • 2
    Possible duplicate of [How to access environment variable values?](https://stackoverflow.com/questions/4906977/how-to-access-environment-variable-values) – Valentin Garreau Aug 26 '19 at 13:17
  • 1
    [Here](https://stackoverflow.com/questions/30180187/setting-an-environment-variable-on-same-line-as-program-execution-is-different-t)'s a link that might help: – blueishpoop Aug 26 '19 at 13:19

1 Answers1

5

Use os.environ (docs), like so:

>>> import os
>>> reportpa = os.environ['REPORTPA']
>>> print(reportpa)
./mypath/mysecondfolder/
chris
  • 1,915
  • 2
  • 13
  • 18
  • 1
    Might not work if OP just does `VAR=value`, but with `export VAR=value` it should be accessible in Python. – tobias_k Aug 26 '19 at 13:13
  • 2
    As long as the `x=y` precedes the command and is on the same line (as it is in OP's post), the export shouldn't be necessary. Give it a try: `REPORTPA=./mypath/mysecondfolder/ python` – chris Aug 26 '19 at 13:16