-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
integration: add background runner script #1594
base: main
Are you sure you want to change the base?
Conversation
To eventually run these in parallel, we want to not have a single test instance hogging the console. Add a background-runner script which uses a detached screen session that also preserves the exit code of the program we're testing.
82b59a9
to
170fba6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems to work and seems like progress!
@@ -0,0 +1,35 @@ | |||
#!/usr/bin/python3 | |||
|
|||
# Use screen to run a terminal program in the background until it exists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/exists/exits/
#!/usr/bin/python3 | ||
|
||
# Use screen to run a terminal program in the background until it exists. | ||
# This process stays around in the forground. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/forground/foreground/
'-D', '-m', # run detached from a terminal perspective, | ||
# but the screen process doesn't background | ||
] | ||
if args.logfile: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is not None?
parser = argparse.ArgumentParser() | ||
parser.add_argument('-l', '--logfile', default=None, | ||
help='append output to logfile') | ||
args, program = parser.parse_known_args() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sadly, there seems to be no way to tell argparse to parse options only at the beginning of the CLI. This means that doing:
scripts/background-runner ls -l /root
will interpret /root
as the logfile for background-runner
, and not an option of ls
.
I suggest to disable prefix matching (i.e., setting allow_abbrev=False
when instantiating ArgumentParser
) to at least avoid stealing options that look like valid background-runner options.
Another alternative is to insert --
between the background-runner
options and the rest of the CLI, e.g.:
scripts/background-runner -- ls -l
but with parse_known_args
, argparse considers --
to be an extra argument, so it ends up first in program
. We would need to remove it manually before calling subprocess.run
:
parser.parse_known_args(["-l", "/tmp/log", "--", "ls", "/root"])
(Namespace(logfile='/tmp/log'), ['--', 'ls', '/root'])
To eventually run these in parallel, we want to not have a single test instance hogging the console. Add a background-runner script which uses a detached screen session that also preserves the exit code of the program we're testing.