From e8807b87e69902840f459279ce38e330b069f53d Mon Sep 17 00:00:00 2001 From: Svein Seldal Date: Sat, 8 Apr 2023 20:45:19 +0200 Subject: [PATCH] Fix pytest on windows (#364) (#365) * Fix pytest on windows (#364) * Slack test even more for WIndows --- setup.cfg | 6 ++++++ test/test_eds.py | 15 +++++++++------ test/test_network.py | 5 ++++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/setup.cfg b/setup.cfg index ca6253b5..7d33e805 100644 --- a/setup.cfg +++ b/setup.cfg @@ -21,3 +21,9 @@ python_requires = >=3.6 install_requires = python-can >= 3.0.0 include_package_data = True + +[tool:pytest] +testpaths = + test +filterwarnings = + ignore::DeprecationWarning diff --git a/test/test_eds.py b/test/test_eds.py index 4977dc10..5edd8d86 100644 --- a/test/test_eds.py +++ b/test/test_eds.py @@ -122,12 +122,15 @@ def test_comments(self): def test_export_eds(self): import tempfile - for doctype in {"eds", "dcf"}: - with tempfile.NamedTemporaryFile(suffix="." + doctype, mode="w+") as tempeds: - print("exporting %s to " % doctype + tempeds.name) - canopen.export_od(self.od, tempeds, doc_type=doctype) - tempeds.flush() - exported_od = canopen.import_od(tempeds.name) + from pathlib import Path + with tempfile.TemporaryDirectory() as tempdir: + for doctype in {"eds", "dcf"}: + tempfile = str(Path(tempdir, "test." + doctype)) + with open(tempfile, "w+") as tempeds: + print("exporting %s to " % doctype + tempeds.name) + canopen.export_od(self.od, tempeds, doc_type=doctype) + + exported_od = canopen.import_od(tempfile) for index in exported_od: self.assertIn(exported_od[index].name, self.od) diff --git a/test/test_network.py b/test/test_network.py index e89ae4dd..04129271 100644 --- a/test/test_network.py +++ b/test/test_network.py @@ -59,7 +59,10 @@ def test_send_perodic(self): task = self.network.send_periodic(0x123, [1, 2, 3], 0.01) time.sleep(0.1) - self.assertTrue(9 <= bus.queue.qsize() <= 11) + # FIXME: This test is a little fragile, as the number of elements + # depends on the timing of the machine. + print("Queue size: %s" % (bus.queue.qsize(),)) + self.assertTrue(9 <= bus.queue.qsize() <= 13) msg = bus.recv(0) self.assertIsNotNone(msg) self.assertSequenceEqual(msg.data, [1, 2, 3])