How to pass arguments to a test?

Asked by Mark Kennedy on 2012-05-24

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.



Question information

English Edit question
selenium-simple-test Edit question
No assignee Edit question
Solved by:
Mark Kennedy
Last query:
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-flags=foo,bar

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:


then in some shared code finding the value like so:

for flag in sst.config.flags:
    if flag.startswith('env:'):
        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('remote:'):
            base_url = flag.split(':', 1)[1]

to switch remotes in my tests:


And achieve exactly what OP asked.