How to pass arguments to a test?
This may be a simple question, but how can I pass arguments to a test? My use case is that I want to be able to pass the environment that I want the test to run in, e.g. local, dev, stage, live? The base URL would be set depending on what was passed in.
Thanks!
MK
Question information
- Language:
- English Edit question
- Status:
- Solved
- Assignee:
- No assignee Edit question
- Solved by:
- Mark Kennedy
- Solved:
- 2012-05-25
- Last query:
- 2012-05-25
- Last reply:
W. Martin Borgert (debacle) said : | #1 |
I'm not sure, wether this is sufficient for you, but maybe you can use flags.
At the command line:
sst-run --with-
In your test code:
import sst.config
if "foo" in sst.config.flags:
...
if "bar" in sst.config.flags:
...
It's just a list of lowercase(!) strings.
Mark Kennedy (mkennedy-u) said : | #2 |
Ah, I see, thanks for the quick answer. I was hoping to be able to pass name/value pairs but have been able to simulate that by passing structured flags like so:
--with-
then in some shared code finding the value like so:
for flag in sst.config.flags:
if flag.startswith
env = flag.split(':')[1]
Works well enough. Thanks again for the reply.
Florian Sesser (fs-8) said : | #3 |
Thank you!
I agree that being able to pass key/value pairs would be useful. I used Mark's snippet, but for a URL, like this:
for flag in sst.config.flags:
if flag.startswith
to switch remotes in my tests:
--with-
And achieve exactly what OP asked.