Skip to content
A Rust (very limited) pytest clone
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
Cargo.toml rstest-6 Version update Jun 27, 2019 #20 Close Apr 12, 2019 #6 Readme Jun 28, 2019

A simple pytest clone for Rust

rstest use procedural macro to implement simple fixtures and table based tests. To use it you need at least 1.30 toolchain and add follow lines to your Cargo.toml file:

rstest = "0.3"

The core idea is that every input arguments of your test function will be resolved by call a function with the same name. Example:

extern crate rstest;

use rstest::rstest;

pub fn fixture() -> u32 { 42 }

fn should_success(fixture: u32) {
    assert_eq!(fixture, 42);

fn should_fail(fixture: u32) {
    assert_ne!(fixture, 42);

Moreover you can use rstest_parametrize macro to implement table based tests. An example is the best way to explain it

extern crate rstest;

use rstest::rstest_parametrize;

    expected, input,
    case(4, "ciao"),
    case(3, "Foo")
fn strlen_test(expected: usize, input: &str) {
    assert_eq!(expected, input.len());

You can learn more on Docs and find more examples in resources directory and in rs8080 that use this module intensely.


Licensed under either of

You can’t perform that action at this time.