Correct invocation of pants to get --help passed through to py.test runner?

82 views
Skip to first unread message

Kevin Sweeney (Twitter)

unread,
Oct 2, 2014, 3:24:12 PM10/2/14
to pants...@googlegroups.com
Not sure if this is a bug or not

I have a PythonTestSuite and I'm trying to pass --help to the underlying py.test runner to see what flags are available. I've tried a variety of invocations [1, 2, 3] but don't seem to be having much luck. Any chance someone on this list knows the correct invocation? I'm using pants 0.0.23.

[1] Stack trace

~aurora git aurora/. master    
% ./pants build src/test/python:all -- --help
Traceback (most recent call last):
  File "/home/ksweeney/workspace/aurora/build-support/pantsbuild.pants-0.0.23.pex/.bootstrap/_twitter_common_python/pex.py", line 223, in execute
    self.execute_entry(entry_point, args)
  File "/home/ksweeney/workspace/aurora/build-support/pantsbuild.pants-0.0.23.pex/.bootstrap/_twitter_common_python/pex.py", line 271, in execute_entry
    runner(entry_point)
  File "/home/ksweeney/workspace/aurora/build-support/pantsbuild.pants-0.0.23.pex/.bootstrap/_twitter_common_python/pex.py", line 294, in execute_pkg_resources
    runner()
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/bin/pants_exe.py", line 196, in main
    _run()
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/bin/pants_exe.py", line 164, in _run
    build_graph)
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/commands/goal_runner.py", line 114, in __init__
    super(GoalRunner, self).__init__(*args, **kwargs)
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/commands/command.py", line 79, in __init__
    self.setup_parser(parser, args)
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/commands/goal_runner.py", line 171, in setup_parser
    goals, specs = GoalRunner.parse_args(non_help_args)
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/commands/goal_runner.py", line 93, in parse_args
    'Cannot intermix targets with goals when using --. Targets should appear on the right')
IntermixedArgumentsError: Cannot intermix targets with goals when using --. Targets should appear on the right


[2] Pants help, not py.test help

% ./pants build src/test/python:all --help   

Usage:
  ./pants goal [option ...] [goal ...] [target...]  Attempt the specified goals.
  ./pants goal help                                 Get help.
  ./pants goal help [goal]                          Get help for the specified goal.
  ./pants goal goals                                List all installed goals.

  [target] accepts two special forms:
    dir:  to include all targets in the specified directory.
    dir:: to include all targets found recursively under the directory.

Friendly docs:

Global options:
  -h, --help              Show this help message.
  -t CONN_TIMEOUT, --timeout=CONN_TIMEOUT
                          Number of seconds to wait for http connections.
  -x, --time              Times goal phases and outputs a report.
  -e, --explain           Explain the execution of goals.
  -k, --kill-nailguns     Kill nailguns before exiting
  -d LOGDIR, --logdir=LOGDIR
                          [none] Write logs to files under this directory.
  -l LOG_LEVEL, --level=LOG_LEVEL
                          [info] Set the logging level [debug, info, warn].
  -q, --quiet             Squelches all console output apart from errors.
  -i INTERPRETER, --interpreter=INTERPRETER
                          Constrain what Python interpreters to use.  Uses
                          Requirement format from pkg_resources, e.g.
                          'CPython>=2.6,<3' or 'PyPy'. By default, no
                          constraints are used.  Multiple constraints may be
                          added.  They will be ORed together.
  --no-colors             Do not colorize log messages.
  --no-lock               Don't attempt to grab the global lock. This lock
                          prevents two concurrent pants instances from stomping
                          on each others data, so only use this if you know what
                          you're doing.
  --read-from-artifact-cache, --no-read-from-artifact-cache
                          Read build artifacts from cache, if available.
  --exclude-target-regexp=TARGET_EXCLUDES
                          Regex pattern to exclude from the target list (useful
                          in conjunction with ::). Multiple patterns may be
                          specified by setting this flag multiple times.
  --write-to-artifact-cache, --no-write-to-artifact-cache
                          Write build artifacts to cache, if possible.
  --print-exception-stacktrace
                          Print to console the full exception stack trace if
                          encountered.

[3] Looks like I tricked the parser into passing -h into the underlying runner - I get this output once per test.

% ./pants build src/test/python:all --hel  
Build operating on top level addresses: set([BuildFileAddress(/home/ksweeney/workspace/aurora/src/test/python/BUILD, all)])
usage: tmpZfYKgX [options] [file_or_dir] [file_or_dir] [...]

positional arguments:
  file_or_dir

general:
  -k EXPRESSION         only run tests which match the given substring
                        expression. An expression is a python evaluatable
                        expression where all names are substring-matched
                        against test names and their parent classes. Example:
                        -k 'test_method or test other' matches all test
                        functions and classes whose name contains
                        'test_method' or 'test_other'. Additionally keywords
                        are matched to classes and functions containing extra
                        names in their 'extra_keyword_matches' set, as well as
                        functions which have names assigned directly to them.
  -m MARKEXPR           only run tests matching given mark expression.
                        example: -m 'mark1 and not mark2'.
  --markers             show markers (builtin, plugin and per-project ones).
  -x, --exitfirst       exit instantly on first error or failed test.
  --maxfail=num         exit after first num failures or errors.
  --strict              run pytest in strict mode, warnings become errors.
  -c file               load configuration from `file` instead of trying to
                        locate one of the implicit configuration files.
  --fixtures, --funcargs
                        show available fixtures, sorted by plugin appearance
  --pdb                 start the interactive Python debugger on errors.
  --capture=method      per-test capturing method: one of fd|sys|no.
  -s                    shortcut for --capture=no.
  --runxfail            run tests even if they are marked xfail

reporting:
  -v, --verbose         increase verbosity.
  -q, --quiet           decrease verbosity.
  -r chars              show extra test summary info as specified by chars
                        (f)ailed, (E)error, (s)skipped, (x)failed, (X)passed
                        (w)warnings.
  -l, --showlocals      show locals in tracebacks (disabled by default).
  --report=opts         (deprecated, use -r)
  --tb=style            traceback print mode (long/short/line/native/no).
  --full-trace          don't cut any tracebacks (default is to cut).
  --color=color         color terminal output (yes/no/auto).
  --durations=N         show N slowest setup/test durations (N=0 for all).
  --pastebin=mode       send failed|all info to bpaste.net pastebin service.
  --junit-xml=path      create junit-xml style report file at given path.
  --junit-prefix=str    prepend prefix to classnames in junit-xml output
  --result-log=path     path for machine-readable result log.

collection:
  --collect-only        only collect tests, don't execute them.
  --pyargs              try to interpret all arguments as python packages.
  --ignore=path         ignore path during collection (multi-allowed).
  --confcutdir=dir      only load conftest.py's relative to specified dir.
  --doctest-modules     run doctests in all .py modules
  --doctest-glob=pat    doctests file matching pattern, default: test*.txt

test session debugging and configuration:
  --basetemp=dir        base temporary directory for this test run.
  --version             display pytest lib version and import information.
  -h, --help            show help message and configuration info
  -p name               early-load given plugin (multi-allowed). To avoid
                        loading of plugins, use the `no:` prefix, e.g.
                        `no:doctest`.
  --trace-config        trace considerations of conftest.py files.
  --debug               store internal tracing debug information in
                        'pytestdebug.log'.
  --assert=MODE         control assertion debugging tools. 'plain' performs no
                        assertion debugging. 'reinterp' reinterprets assert
                        statements after they failed to provide assertion
                        expression information. 'rewrite' (the default)
                        rewrites assert statements in test modules on import
                        to provide assert expression information.
  --no-assert           DEPRECATED equivalent to --assert=plain
  --no-magic            DEPRECATED equivalent to --assert=plain
  --genscript=path      create standalone pytest script at given target path.

coverage reporting with distributed testing support:
  --cov=path            measure coverage for filesystem path (multi-allowed)
  --cov-report=type     type of report to generate: term, term-missing,
                        annotate, html, xml (multi-allowed)
  --cov-config=path     config file for coverage, default: .coveragerc
  --no-cov-on-fail      do not report coverage if test run fails, default:
                        False

Interrupt test run and dump stacks of all threads after a test times out:
  --timeout=TIMEOUT     Timeout in seconds before dumping the stacks. Default
                        is 0 which means no timeout.
  --timeout_method={signal,thread}
                        Depreacted, use --timeout-method
  --timeout-method={signal,thread}
                        Timeout mechanism to use. 'signal' uses SIGALRM if
                        available, 'thread' uses a timer thread. The default
                        is to use 'signal' and fall back to 'thread'.


[pytest] ini-options in the next pytest.ini|tox.ini|setup.cfg file:

  markers (linelist)       markers for test functions
  norecursedirs (args)     directory patterns to avoid for recursion
  usefixtures (args)       list of default fixtures to be used with this project
  python_files (args)      glob-style file patterns for Python test module discovery
  python_classes (args)    prefixes for Python test class discovery
  python_functions (args)  prefixes for Python test function and method discovery
  addopts (args)           extra command line options
  minversion (string)      minimally required pytest version
  timeout (string)         Timeout in seconds before dumping the stacks.  Default is 0 which
means no 
  timeout_method (string)  Timeout mechanism to use.  'signal' uses SIGALRM if available,
'thread' use


to see available markers type: py.test --markers
to see available fixtures type: py.test --fixtures
(shown according to specified file_or_dir or current dir if not specified)
[...repeats once for each test]

Larry Hosken

unread,
Oct 2, 2014, 3:38:13 PM10/2/14
to Kevin Sweeney (Twitter), pants-devel
Give Pants' newfangled 'goal' invocation a whirl. This gave me some
help-ish looking output in the pants repo, where
"tests/python/pants_test/targets/:" are some Python test targets:

$ ./pants goal test --test-pytest-options='--help'
tests/python/pants_test/targets/:

Benjy Weinberger

unread,
Oct 2, 2014, 3:44:04 PM10/2/14
to Larry Hosken, Kevin Sweeney (Twitter), pants-devel
Do you mean pytest's own flags? We don't expose those in pants's help, so you'll have to look for it online here: http://pytest.org/latest/usage.html

Kevin Sweeney

unread,
Oct 2, 2014, 4:30:37 PM10/2/14
to Benjy Weinberger, Larry Hosken, pants-devel
pytest itself exposes them when invoked with --help, but I can't seem to pass it that flag (I can pass it others, however)

When I try the goal invocation I get an error about a missing nailgun-server, which doesn't make a lot of sense to me since this repo only uses Pants to build and test Python.

~aurora git aurora/. master    
% ./pants goal test src/test/python:all --test-pytest-options='--help'

13:17:32 00:00 [main]
               (To run a reporting server: ./pants goal server)
13:17:32 00:00   [bootstrap]
13:17:32 00:00   [setup]
13:17:32 00:00     [parse]
               Executing goals in phases: bootstrap -> imports -> gen -> check-exclusives -> resolve -> compile -> resources -> test
13:17:32 00:00   [bootstrap]
13:17:32 00:00     [bootstrap-jvm-tools]
13:17:32 00:00   [imports]
13:17:32 00:00     [ivy-imports]
13:17:32 00:00   [gen]
13:17:32 00:00     [thrift]
13:17:32 00:00     [scrooge]
13:17:32 00:00     [protoc]
13:17:32 00:00     [antlr]
13:17:32 00:00     [ragel]
13:17:32 00:00     [jaxb]
13:17:32 00:00     [aapt]
13:17:32 00:00   [check-exclusives]
13:17:32 00:00     [check-exclusives]
13:17:32 00:00   [resolve]
13:17:32 00:00     [ivy]
               FAILURE
Traceback (most recent call last):
  File "/home/ksweeney/workspace/aurora/build-support/pantsbuild.pants-0.0.23.pex/.bootstrap/_twitter_common_python/pex.py", line 223, in execute
    self.execute_entry(entry_point, args)
  File "/home/ksweeney/workspace/aurora/build-support/pantsbuild.pants-0.0.23.pex/.bootstrap/_twitter_common_python/pex.py", line 271, in execute_entry
    runner(entry_point)
  File "/home/ksweeney/workspace/aurora/build-support/pantsbuild.pants-0.0.23.pex/.bootstrap/_twitter_common_python/pex.py", line 294, in execute_pkg_resources
    runner()
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/bin/pants_exe.py", line 196, in main
    _run()
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/bin/pants_exe.py", line 177, in _run
    result = command.run(lock)
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/commands/goal_runner.py", line 297, in run
    return engine.execute(context, self.phases)
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/engine/engine.py", line 49, in execute
    self.attempt(context, phases)
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/engine/round_engine.py", line 186, in attempt
    phase_executor.attempt(explain)
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/engine/round_engine.py", line 42, in attempt
    task.execute()
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/backend/jvm/tasks/ivy_resolve.py", line 104, in execute
    executor = self.create_java_executor()
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/backend/jvm/tasks/nailgun_task.py", line 76, in create_java_executor
    classpath = os.pathsep.join(self.tool_classpath(self._nailgun_bootstrap_key))
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/backend/jvm/tasks/jvm_tool_task_mixin.py", line 24, in tool_classpath
    return self.jvm_tool_bootstrapper.get_jvm_tool_classpath(key, executor)
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/backend/jvm/jvm_tool_bootstrapper.py", line 21, in get_jvm_tool_classpath
    return self.get_lazy_jvm_tool_classpath(key, executor)()
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/backend/jvm/jvm_tool_bootstrapper.py", line 32, in <lambda>
    return lambda: callback(executor=executor)
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/backend/jvm/tasks/bootstrap_jvm_tools.py", line 82, in bootstrap_classpath
    targets = list(self.resolve_tool_targets(tools))
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/backend/jvm/tasks/bootstrap_jvm_tools.py", line 63, in resolve_tool_targets
    targets = list(self.context.resolve(tool))
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/goal/context.py", line 285, in resolve
    self.build_file_parser.inject_spec_closure_into_build_graph(spec, self.build_graph)
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/base/build_file_parser.py", line 145, in inject_spec_closure_into_build_graph
    addresses_already_closed)
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/base/build_file_parser.py", line 155, in _inject_spec_closure_into_build_graph
    self.inject_address_closure_into_build_graph(address, build_graph, addresses_already_closed)
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/base/build_file_parser.py", line 102, in inject_address_closure_into_build_graph
    self._populate_target_proxy_transitive_closure_for_address(address)
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/base/build_file_parser.py", line 236, in _populate_target_proxy_transitive_closure_for_address
    self._raise_incorrect_target_error(address, self._target_proxy_by_address.keys())
  File "/home/ksweeney/.pex/install/pantsbuild.pants-0.0.23-py2-none-any.whl.fd4e72ce8848430b51d614ea7daf243505ca94fc/pantsbuild.pants-0.0.23-py2-none-any.whl/pants/base/build_file_parser.py", line 214, in _raise_incorrect_target_error
    build_file=wrong_target.build_file))
EmptyBuildFileException: :nailgun-server from spec :nailgun-server was not found in BUILD file /home/ksweeney/workspace/aurora/BUILD, because that BUILD file contains no targets.

--
Kevin Sweeney
@kts

Larry Hosken

unread,
Oct 2, 2014, 4:38:50 PM10/2/14
to Kevin Sweeney, Benjy Weinberger, pants-devel
> When I try the goal invocation I get an error about a
> missing nailgun-server, which doesn't make a lot of
> sense to me since this repo only uses Pants to build
> and test Python.

D'oh, yeah.
Python goals shouldn't depend on JVM things like nailgun.
But it's not surprising to hear that they do :-(

-Larry H.
Reply all
Reply to author
Forward
0 new messages