Skip to content

Instantly share code, notes, and snippets.

@scivision
Last active March 7, 2023 05:21
Embed
What would you like to do?
Pytest with Matlab and GNU Octave
# /usr/bin/env python3
from pathlib import Path
import subprocess
import pytest
import shutil
import functools
R = Path(__file__).parent
@functools.cache
def octave() -> str | None:
return shutil.which("octave")
@functools.cache
def matlab() -> str | None:
return shutil.which("matlab")
@pytest.mark.skipif(not matlab(), reason="Matlab not available")
def test_matlab_api():
subprocess.check_call(
[
matlab(),
"-batch",
f"r=runtests('{R}'), assert(~isempty(r)), assertSuccess(r)",
],
timeout=60,
)
@pytest.mark.skipif(not octave(), reason="octave not found")
def test_octave_api():
subprocess.check_call([octave(), "oruntests('{R}')"], timeout=60)
classdef TestExample < matlab.unittest.TestCase
methods (Test)
function testExample(testCase)
testCase.verifyEqual(1, 1);
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment