• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pantsbuild / pants / 35147
0%
main: 93%

Build:
Build:
LAST BUILD BRANCH: pants_lock
DEFAULT BRANCH: main
Ran 29 Aug 2020 12:27AM UTC
Jobs 1
Files 430
Run time 23s
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

pending completion
35147

push

travis-ci-com

web-flow
Add `RuleRunner` as a Pytest-style replacement to `TestBase` (#10699)

## Problem

We want to be able to use Pytest-style tests, rather than unittest style tests. Pytest allows for nice features like parameterization and fixtures, including dozens of pre-built fixtures like `caplog` (capture logging).

For our `TestBase`-style tests, we need a wrapper around a `SchedulerSession` in order to make synchronous calls to the engine. We also need to set up a temporary build root.

For isolation between tests, we must be careful to invalidate every test, such as using a new build root every individual test.

## Solution

Add `RuleRunner`, which is a dataclass around all the config necessary to create a `BuildConfiguration` and `SchedulerSession`. This dataclass exposes the methods `request_product()` and `run_goal_rule()`, along with utilities like `add_to_build_file()`.

Each individual test should create a new instance of a `RuleRunner`. This is important for isolation between tests.

Conventionally, this will be done with a [Pytest fixture](https://docs.pytest.org/en/stable/fixture.html), which allows us to set up common config (e.g. rules and target types) for multiple tests but to still get a distinct `RuleRunner` instance for each test.

```python
@pytest.fixture
def rule_runner() -> RuleRunner:
    return RuleRunner(rules=filedeps.rules(), target_types=[MockTarget, ProtobufLibrary])

def test_no_target(rule_runner: RuleRunner) -> None:
    rule_runner.create_file(...)
    rule_runner.request_product(..)

```

Users can also create the `RuleRunner` inline.

If there are multiple different configurations in a test file, the user may set up multiple different Pytest fixtures.

```python
@pytest.fixture
def target_adaptor_rule_runner() -> RuleRunner:
    return RuleRunner(
        rules=[QueryRule(TargetAdaptor, (Address, OptionsBootstrapper))], target_types=[MockTgt]
    )

...

@pytest.fixture
def address_specs_r... (continued)

0 of 28923 relevant lines covered (0.0%)

0.0 hits per line

Jobs
ID Job ID Ran Files Coverage
4 35147.4 (PANTS_CONFIG_FILES="${TRAVIS_BUILD_DIR}/pants.travis-ci.toml" PANTS_DYNAMIC_UI=false LC_ALL="en_US.UTF-8" AWS_BUCKET=ci-public.pantsbuild.org BOOTSTRAPPED_PEX_KEY_PREFIX=daily/${TRAVIS_BUILD_NUMBER}/${TRAVIS_BUILD_ID}/pants.pex NATIVE_ENGINE_SO_KEY_PREFIX=monthly/native_engine_so PYENV_PY27_VERSION=2.7.18 PYENV_PY36_VERSION=3.6.10 PYENV_PY37_VERSION=3.7.7 PYENV_PY38_VERSION=3.8.3 PYENV_ROOT_OSX=${HOME}/.pants_pyenv PYENV_ROOT="${PYENV_ROOT:-${PYENV_ROOT_OSX}}" PATH="${PYENV_ROOT}/shims:${PATH}" AWS_CLI_ROOT="${HOME}/.aws_cli" AWS_ACCESS_KEY_ID__TO_BE_REEXPORTED_ON_DEPLOYS=AKIAV6A6G7RQ2HFZ5KP7 AWS_SECRET_ACCESS_KEY=[secure] RUST_BACKTRACE="all" BOOTSTRAPPED_PEX_KEY_SUFFIX=py36.linux PANTS_REMOTE_CA_CERTS_PATH=/usr/lib/google-cloud-sdk/lib/third_party/grpc/_cython/_credentials/roots.pem CACHE_NAME=python_tests.py36) 29 Aug 2020 12:27AM UTC 0
0.0
Travis Job 35147.4
Source Files on build 35147
Detailed source file information is not available for this build.
  • Back to Repo
  • Build #35147
  • d3eee59e on github
  • Prev Build on master (#35137)
  • Next Build on master (#35150)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc