ali5h / rules_pip

pip package rules for bazel that are fast (incremental fetch), support different python versions and work with all kinds of packages (i.e. packages with namespaces)
MIT License
60 stars 24 forks source link

pytest: allow customising test runner args #26

Closed tommilligan closed 4 years ago

tommilligan commented 4 years ago

I'd like to customise the arguments that are passed to pytest by the py_pytest_test rule. My usecase is I only want to test files in a specific directory, and currently the "." (test this directory) argument is hardcoded.

This PR moves the default arguments from pytest_helper.py into the defs.bzl definition, so they can be overridden. For backwards compatibility, they have been named as a new argument, pytest_args, rather than just args.

These can then be adjusted like so:

py_pytest_test(
    ...
    args = ["$(locations :lib_test)"],
    pytest_args = [
        "-vv",
        "--ignore=external",
        "-p",
        "no:cacheprovider",
    ],
)
ali5h commented 4 years ago

. always points to runfiles of the tests, so whatever test is included in srcs will be executed. If you want to limit the tests you want to run, only include those in srcs

tommilligan commented 4 years ago

You're right that it will execute all tests in srcs as these are stored in runfiles, however also included here are files passed in via deps (and data I guess, although I haven't tested that).

For my use case specifically, I'm working on a codebase where test files are importing helper functions from another module's test file, and I don't want tests from that external file to be run.