Minitest against pytest

One class, two tests

A test is a test in both languages: call a method, compare the result, report one line. The class under test is a single method that adds two numbers, written once in Ruby and once in Python.

class Calc def add(a, b) a + b end end

def add(a, b): return a + b

Minitest does not need a file name convention: the test requires the library and names a class.

require "minitest/autorun" require_relative "../lib/calc" class CalcTest < Minitest::Test def test_add assert_equal 4, Calc.new.add(2, 2) end end

pytest finds the test by its file name and its function name; no class and no require line are needed.

from calc import add def test_add(): assert add(2, 2) == 4

Run both

ruby -Itest test/calc_test.rb

Run options: --seed 44186

# Running:

.

Finished in 0.000722s, 1385.2891 runs/s, 1385.2891 assertions/s.

1 runs, 1 assertions, 0 failures, 0 errors, 0 skips

python3 -m pytest -q

.
1 passed in 0.01s

Minitest prints a run header, a dot per test and a summary line. pytest with -q prints a dot and one line. Both exit zero, which is the only part a pipeline reads.

What differs

What to watch for

A pipeline reads the exit code and the report file, not the pretty output. Lesson 57 turns Minitest into JUnit XML; pytest --junitxml=report.xml does the same on the Python side, so a mixed repository can feed both into one report view.

Run the tests through the project task (rake test, pytest), not through a hand-written file list. The wrapper is where the seed, the report and the coverage flags go, and both pipelines then call one command.

Next: Gems against pip

Article author: Arthur Isaev