outside-process

A test reaches the network or starts another process.

Group
Tests
Runs
On by default
Level
note
Reads
Tests
Fix
None: whether the test is meant to be a larger test is the author's to say
Defends
Resilience: the test fails only when the code is broken.

Why

The test, a closure it writes, or a helper of its file that only it calls opens a network connection or starts another process. A small test does neither: it fails when the other end is slow, absent, or changed, whatever the code under test does. A test that is meant to be larger keeps the finding with an ur-allow comment.

The fix, as Ur suggests it: replace what the test reaches with a fake, or mark a test that is meant to be larger with ur-allow: outside-process.

For agents

Keep a test inside its own process: replace a server or a program it would reach with a fake or an in-memory implementation.

Example

shop/rates.py
def convert(amount, rate):
    return round(amount * rate, 2)
tests/test_rates.py
import requests

from shop.rates import convert


def test_converts_at_the_published_rate():
    rate = requests.get("https://rates.example.com/eur").json()["rate"]
    assert convert(10, rate) > 0
What Ur prints
$ ur lint --rule outside-process
note[outside-process]: test `test_converts_at_the_published_rate` reaches the network with `requests.get`
  --> ./tests/test_rates.py:7:12 test `test_converts_at_the_published_rate`
  = hint: replace what the test reaches with a fake, or mark a test that is meant to be larger with `ur-allow: outside-process`
  = see: Test Sizes, Google Testing Blog (2010-12-13), https://testing.googleblog.com/2010/12/test-sizes.html
0 clone classes and 1 test finding in 2 files

Try it in the playground →

Source

Test Sizes, Google Testing Blog (2010-12-13).