0

I am trying to parametrize a call to pytest like this:

export OPTIONS="tests -k 'not e2e'"
pytest ${OPTIONS}

The pytest call fails because of the quotes in the variable. Putting the options directly in the call works fine.

I tried:

pytest ${OPTIONS} 
ERROR: file not found: tests -k 'not e2e'

pytest $(eval echo "${OPTIONS}") # removes all quotes
ERROR: file not found: e2e

pytest $(printf %s ${OPTIONS})

How can I make the pytest call work in a parametrized way?

UPDATE

This answer contains a solution that works:

eval "OPTIONS=($OPTIONS)" # (opt.) convert an existing string to an array

export OPTIONS=(tests -k 'not e2e')
pytest "${OPTIONS[@]}"

Thank you very much for pointing that out. I was already searching for hours.

  • Note: the linked duplicate is about storing commands in a variable but the top answer also details storing command options in an array, as well as several other solutions that would also work for this issue. – jesse_b Oct 11 '19 at 17:06
  • How can we run a command stored in a variable? has the whole command in the variable vs. here it's just the arguments. It doesn't matter though, the issue is how the variable expands, having a fixed command name (or some other fixed arguments around it) doesn't change that. (the shell doesn't really process the command name any differently from the other arguments.) – ilkkachu Oct 11 '19 at 20:10
  • How could this work in a sh or ash environment which do not support arrays? – chbndrhnns Oct 14 '19 at 08:43

1 Answers1

0

Has you tried this?

export OPTIONS="tests -k \'not e2e\'"

It must work with eval

LeoLopez
  • 101