class mpf.tests.MpfTestCase.TestMachineController(mpf_path, machine_path, options, config_patches, config_defaults, clock, mock_data, enable_plugins=False)

Bases: mpf.core.machine.MachineController

A patched version of the MachineController used in tests.

The TestMachineController has a few changes from the regular machine controller to facilitate running unit tests, including:

  • Use the TestDataManager instead of the real one.
  • Use a test clock which we can manually advance instead of the regular clock tied to real-world time.
  • Only load plugins if self._enable_plugins is True.
  • Merge any test_config_patches into the machine config.
  • Disabled the config file caching to always load the config from disk.

Methods & Attributes

The TestMachineController has the following methods & attributes available. Note that methods & attributes inherited from the base class are not included here.

add_platform(name: str) → None

Make an additional hardware platform interface available to MPF.

Parameters:name – String name of the platform to add. Must match the name of a platform file in the mpf/platforms folder (without the .py extension).
clear_boot_hold(hold: str) → None

Clear a boot hold.

configure_machine_var(name: str, persist: bool, expire_secs: int = None) → None

Create a new machine variable.

  • name – String name of the variable.
  • persist – Boolean as to whether this variable should be saved to disk so it’s available the next time MPF boots.
  • expire_secs – Optional number of seconds you’d like this variable to persist on disk for. When MPF boots, if the expiration time of the variable is in the past, it will not be loaded. For example, this lets you write the number of credits on the machine to disk to persist even during power off, but you could set it so that those only stay persisted for an hour.

Return a new DataManager for a certain config.

Parameters:config_name – Name of the config
get_machine_var(name: str) → Any

Return the value of a machine variable.

Parameters:name – String name of the variable you want to get that value for.
Returns:The value of the variable if it exists, or None if the variable does not exist.
get_platform_sections(platform_section: str, overwrite: str) → SmartVirtualHardwarePlatform

Return platform section.

ignorable_runtime_exception(msg: str) → None

Handle ignorable runtime exception.

During development or tests raise an exception for easier debugging. Log an error during production.

init_done() → Generator[[int, None], None]

Finish init.

Called when init is done and all boot holds are cleared.

initialise() → Generator[[int, None], None]

Initialise machine.

initialise_core_and_hardware() → Generator[[int, None], None]

Load core modules and hardware.


Initialise MPF.

is_machine_var(name: str) → bool

Return true if machine variable exists.

raise_config_error(msg, error_no, *, context=None)

Raise a ConfigFileError exception.

register_boot_hold(hold: str) → None

Register a boot hold.

register_monitor(monitor_class: str, monitor: Callable[..., Any]) → None

Register a monitor.

  • monitor_class – String name of the monitor class for this monitor that’s being registered.
  • monitor – Callback to notify

MPF uses monitors to allow components to monitor certain internal elements of MPF.

For example, a player variable monitor could be setup to be notified of any changes to a player variable, or a switch monitor could be used to allow a plugin to be notified of any changes to any switches.

The MachineController’s list of registered monitors doesn’t actually do anything. Rather it’s a dictionary of sets which the monitors themselves can reference when they need to do something. We just needed a central registry of monitors.

remove_machine_var(name: str) → None

Remove a machine variable by name.

If this variable persists to disk, it will remove it from there too.

Parameters:name – String name of the variable you want to remove.

Remove a machine variable by matching parts of its name.

  • startswith – Optional start of the variable name to match.
  • endswith – Optional end of the variable name to match.

For example, if you pass startswit=’player’ and endswith=’score’, this method will match and remove player1_score, player2_score, etc.

reset() → Generator[[int, None], None]

Reset the machine.

This method is safe to call. It essentially sets up everything from scratch without reloading the config files and assets from disk. This method is called after a game ends and before attract mode begins.

run() → None

Start the main machine run loop.

set_default_platform(name: str) → None

Set the default platform.

It is used if a device class-specific or device-specific platform is not specified.

Parameters:name – String name of the platform to set to default.
set_machine_var(name: str, value: Any) → None

Set the value of a machine variable.

  • name – String name of the variable you’re setting the value for.
  • value – The value you’re setting. This can be any Type.
shutdown() → None

Shutdown the machine.

stop(**kwargs) → None

Perform a graceful exit of MPF.

validate_machine_config_section(section: str) → None

Validate a config section.


Dump information about the Python installation to the log.

Information includes Python version, Python executable, platform, and core architecture.

warning_log(msg: str, *args, context=None, **kwargs) → None

Log a message at the warning level.

These messages will always be shown in the console and the log file.