Custom Test Support

pytest fixtures

class pyfrc.test_support.pytest_plugin.PyFrcPlugin(robot_class, robot_file)[source]

Pytest plugin. Each documented member function name can be an argument to your test functions, and the data that these functions return will be passed to your test function.

control(reraise, robot)[source]

A pytest fixture that provides control over your robot

Return type:

TestController

robot()[source]

Your robot instance

Note

RobotPy/WPILib testing infrastructure is really sensitive to ensuring that things get cleaned up properly. Make sure that you don’t store references to your robot or other WPILib objects in a global or static context.

robot_file()[source]

The absolute filename your robot code is started from

Return type:

Path

robot_path()[source]

The absolute directory that your robot code is located at

Return type:

Path

Controlling the robot’s state

class pyfrc.test_support.controller.TestController(reraise, robot)[source]

Use this object to control the robot’s state during tests

property robot_is_alive: bool

True if the robot code is alive

run_robot()[source]

Use this in a “with” statement to start your robot code at the beginning of the with block, and end your robot code at the end of the with block.

Your robotInit function will not be called until this function is called.

step_timing(*, seconds, autonomous, enabled, assert_alive=True)[source]

This utility will increment simulated time, while pretending that there’s a driver station connected and delivering new packets every 0.2 seconds.

Parameters:
  • seconds (float) – Number of seconds to run (will step in increments of 0.2)

  • autonomous (bool) – Tell the robot that it is in autonomous mode

  • enabled (bool) – Tell the robot that it is enabled

Return type:

float

Returns:

Number of seconds time was incremented