From 83ccfe6f4df59a63a81ab1b7ea567f6363d8f5ef Mon Sep 17 00:00:00 2001 From: Jammu Kekkonen Date: Tue, 24 Oct 2023 17:53:38 +0800 Subject: [PATCH] test(serial.py): add test for file description leak --- pytest-embedded-serial/tests/test_serial.py | 60 +++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/pytest-embedded-serial/tests/test_serial.py b/pytest-embedded-serial/tests/test_serial.py index b262f84d..30b93207 100644 --- a/pytest-embedded-serial/tests/test_serial.py +++ b/pytest-embedded-serial/tests/test_serial.py @@ -51,3 +51,63 @@ def test_teardown_called_for_multi_dut_succeeded(dut): result = testdir.runpytest() result.assert_outcomes(passed=1, errors=1) + + +def test_serial_file_description_leak(testdir): + testdir.makepyfile(r""" + import pytest + from pytest_lazyfixture import lazy_fixture + + + dutHelper = None + + + class DutHelper: + def __init__(self): + self.duts = None + + def setDut(self, duts): + self.duts = duts + + def dut1(self): + return self.duts[0] + + def dut2(self): + return self.duts[1] + + + @pytest.fixture + def dut_helper(dut): + global dutHelper + if dutHelper is None: + dutHelper = DutHelper() + dutHelper.setDut(dut) + return dutHelper + + + @pytest.fixture + def DUT1(dut_helper): + return dut_helper.dut1() + + + @pytest.fixture + def DUT2(dut_helper): + return dut_helper.dut2() + + + @pytest.mark.parametrize("fixture", [lazy_fixture("DUT1"), lazy_fixture("DUT2")]) + @pytest.mark.parametrize("test_input", range(0, 300)) + def test_dummy(test_input, dut, fixture): + dut[0].write("foo") + assert test_input == test_input + + """) + + result = testdir.runpytest( + '-s', + '--count', 2, + '--embedded-services', 'serial|serial', + '--port', '/dev/ttyUSB0|/dev/ttyUSB1', + '--baud', '115200|115200' + ) + result.assert_outcomes(passed=600)