support/testing: add pytest test
authorMarcin Niestroj <m.niestroj@grinn-global.com>
Tue, 1 Sep 2020 17:16:45 +0000 (19:16 +0200)
committerThomas Petazzoni <thomas.petazzoni@bootlin.com>
Sun, 6 Sep 2020 12:46:41 +0000 (14:46 +0200)
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
DEVELOPERS
support/testing/tests/package/sample_python_pytest.py [new file with mode: 0644]
support/testing/tests/package/test_python_pytest.py [new file with mode: 0644]

index c85dd355d422cc56bae851eda337e8e6b1ed73ca..d7efc87ea45873f0c0a076ee670dd103673a0ed7 100644 (file)
@@ -1631,7 +1631,9 @@ F:        package/python-pluggy/
 F:     package/python-pytest/
 F:     package/rs485conf/
 F:     package/turbolua/
+F:     support/testing/tests/package/sample_python_pytest.py
 F:     support/testing/tests/package/test_netdata.py
+F:     support/testing/tests/package/test_python_pytest.py
 
 N:     Marcus Folkesson <marcus.folkesson@gmail.com>
 F:     package/libostree/
diff --git a/support/testing/tests/package/sample_python_pytest.py b/support/testing/tests/package/sample_python_pytest.py
new file mode 100644 (file)
index 0000000..870cc85
--- /dev/null
@@ -0,0 +1,25 @@
+import pytest
+
+
+x = 1
+
+
+@pytest.fixture()
+def f1():
+    global x
+    x = 2
+    yield 15
+    x = 3
+
+
+def test_1():
+    assert x == 1
+
+
+def test_2(f1):
+    assert x == 2
+    assert f1 == 15
+
+
+def test_3():
+    assert x == 3
diff --git a/support/testing/tests/package/test_python_pytest.py b/support/testing/tests/package/test_python_pytest.py
new file mode 100644 (file)
index 0000000..7fa7e44
--- /dev/null
@@ -0,0 +1,19 @@
+import os
+
+from tests.package.test_python import TestPythonPackageBase
+
+
+class TestPythonPy3Pytest(TestPythonPackageBase):
+    __test__ = True
+    config = TestPythonPackageBase.config + \
+        """
+        BR2_PACKAGE_PYTHON3=y
+        BR2_PACKAGE_PYTHON_PYTEST=y
+        """
+    sample_scripts = ["tests/package/sample_python_pytest.py"]
+
+    def run_sample_scripts(self):
+        for script in self.sample_scripts:
+            cmd = self.interpreter + " -m pytest " + os.path.basename(script)
+            _, exit_code = self.emulator.run(cmd, timeout=self.timeout)
+            self.assertEqual(exit_code, 0)