How to pass command line arguments to a rake task

You can specify formal arguments in rake by adding symbol arguments to the task call. For example: require ‘rake’ task :my_task, [:arg1, :arg2] do |t, args| puts “Args were: #{args} of class #{args.class}” puts “arg1 was: ‘#{args[:arg1]}’ of class #{args[:arg1].class}” puts “arg2 was: ‘#{args[:arg2]}’ of class #{args[:arg2].class}” end task :invoke_my_task do Rake.application.invoke_task(“my_task[1, 2]”) end # … Read more

How to pass arguments in pytest by command line

In your pytest test, don’t use @pytest.mark.parametrize: def test_print_name(name): print (“Displaying name: %s” % name) In conftest.py: def pytest_addoption(parser): parser.addoption(“–name”, action=”store”, default=”default name”) def pytest_generate_tests(metafunc): # This is called for every test. Only get/set command line arguments # if the argument is specified in the list of test “fixturenames”. option_value = metafunc.config.option.name if ‘name’ in … Read more

Windows is not passing command line arguments to Python programs executed from the shell

I think I solved this. For some reason there is a SECOND place in the registry (besides that shown by the file associations stored in HKEY_CLASSES_ROOT\Python.File\shell\open\command): [HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command] @=”\”C:\\Python25\\python.exe\” \”%1\” %*” This seems to be the controlling setting on my system. The registry setting above adds the “%*” to pass all arguments to python.exe (it was … Read more

What’s the best way to parse command line arguments? [closed]

argparse is the way to go. Here is a short summary of how to use it: 1) Initialize import argparse # Instantiate the parser parser = argparse.ArgumentParser(description=’Optional app description’) 2) Add Arguments # Required positional argument parser.add_argument(‘pos_arg’, type=int, help=’A required integer positional argument’) # Optional positional argument parser.add_argument(‘opt_pos_arg’, type=int, nargs=”?”, help=’An optional integer positional argument’) … Read more

How do I do the bash equivalent of $PROGPATH/program in Powershell?

js2010’s helpful answer shows the correct solution: Because your command name/path contains a variable reference ($PROGPATH/…), you must invoke it with &. The same applies if a grouping expression, (…) is used, or a subexpression, $(…) is involved. Additionally, the same applies if a command name/path is quoted (‘…’ or “…”)[1], as is required if … Read more