Skip to content

Commit 301d1b2

Browse files
committed
make tests runnable in parallel
Avoid hard-coded file names and non-local objects. Mark tests that cannot be run in parallel.
1 parent 0b216de commit 301d1b2

15 files changed

+65
-49
lines changed

test/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
BUILD_DIR = "build/lib.{}-{}.{}".format(sysconfig.get_platform(),
2020
sys.version_info[0], sys.version_info[1])
2121

22-
2322
if not (SRC_DIR / BUILD_DIR).exists():
24-
BUILD_DIR = "build/lib.{}-{}".format(sysconfig.get_platform(),
25-
sys.implementation.cache_tag)
23+
BUILD_DIR = "build/lib.{}-{}{}".format(sysconfig.get_platform(),
24+
sys.implementation.cache_tag,
25+
getattr(sys, 'abiflags', ''))
2626

2727
if (SRC_DIR / BUILD_DIR).exists():
2828
sys.path.insert(0, str(SRC_DIR))

test/test_area.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# For a full list of authors see the git log.
77
from pathlib import Path
88

9+
import pytest
910
import osmium
1011

1112
from helpers import CountingHandler
@@ -14,6 +15,7 @@
1415
TEST_FILE = str((Path(__file__) / '..' / 'example-test.pbf').resolve())
1516

1617

18+
@pytest.mark.thread_unsafe
1719
def test_area_handler():
1820
area = osmium.area.AreaManager()
1921

test/test_back_reference_writer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Copyright (C) 2025 Sarah Hoffmann <[email protected]> and others.
66
# For a full list of authors see the git log.
77
import pytest
8+
import uuid
89

910
import osmium
1011

@@ -18,7 +19,7 @@ class TestWay:
1819
id = 34
1920
nodes = [3, 6, 5]
2021

21-
outfile = str(tmp_path / 'test.osm')
22+
outfile = str(tmp_path / f'{uuid.uuid4()}.osm')
2223

2324
with osmium.BackReferenceWriter(outfile, ref_file) as writer:
2425
writer.add_way(TestWay())
@@ -33,7 +34,7 @@ class TestWay:
3334

3435
def test_do_not_write_on_exception(test_data, tmp_path):
3536
ref_file = test_data('\n'.join((f"n{i} x2 y3" for i in range(10))))
36-
outfile = tmp_path / 'test.osm'
37+
outfile = tmp_path / f'{uuid.uuid4()}.osm'
3738

3839
with pytest.raises(RuntimeError, match="inner error"):
3940
with osmium.BackReferenceWriter(str(outfile), ref_file):

test/test_dangling_references.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import pytest
1010
import osmium
1111

12+
pytestmark = pytest.mark.iterations(1)
13+
1214
TEST_DIR = (Path(__file__) / '..').resolve()
1315

1416

test/test_empty_tag_filter.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
@pytest.fixture
1414
def reader(opl_reader):
15-
return opl_reader("""\
15+
def _mk():
16+
return opl_reader("""\
1617
n1 x1 y1
1718
n2 x1 y1 Tfoo=bar
1819
w1 Nn1,n2 Thighway=road
@@ -23,11 +24,13 @@ def reader(opl_reader):
2324
c223
2425
""")
2526

27+
return _mk
28+
2629

2730
def test_filter_default_config(reader):
2831
pre = IDCollector()
2932
post = IDCollector()
30-
osmium.apply(reader, pre, osmium.filter.EmptyTagFilter(), post)
33+
osmium.apply(reader(), pre, osmium.filter.EmptyTagFilter(), post)
3134

3235
assert pre.nodes == [1, 2]
3336
assert post.nodes == [2]
@@ -42,7 +45,7 @@ def test_filter_default_config(reader):
4245
def test_filter_restrict_entity(reader):
4346
pre = IDCollector()
4447
post = IDCollector()
45-
osmium.apply(reader, pre,
48+
osmium.apply(reader(), pre,
4649
osmium.filter.EmptyTagFilter().enable_for(osmium.osm.WAY | osmium.osm.RELATION),
4750
post)
4851

@@ -57,7 +60,7 @@ def test_filter_restrict_entity(reader):
5760
def test_filter_chained(reader):
5861
pre = IDCollector()
5962
post = IDCollector()
60-
osmium.apply(reader, pre,
63+
osmium.apply(reader(), pre,
6164
osmium.filter.EmptyTagFilter().enable_for(osmium.osm.NODE),
6265
osmium.filter.EmptyTagFilter().enable_for(osmium.osm.WAY),
6366
post)

test/test_examples.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"""
1010
from pathlib import Path
1111

12+
import pytest
1213

1314
TEST_DIR = (Path(__file__) / '..').resolve()
1415
TEST_FILE = TEST_DIR / 'example-test.pbf'
@@ -26,6 +27,7 @@ def run_example(name, *args):
2627

2728

2829
def test_amenity_list(capsys):
30+
pytest.importorskip("shapely")
2931
assert 0 == run_example("amenity_list", TEST_FILE)
3032

3133
output = capsys.readouterr().out.splitlines()

test/test_file_processor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Copyright (C) 2025 Sarah Hoffmann <[email protected]> and others.
66
# For a full list of authors see the git log.
77
import pytest
8+
import uuid
89

910
import osmium
1011
from helpers import IDCollector
@@ -125,7 +126,7 @@ def test_generator_with_filter(opl_buffer):
125126

126127

127128
def test_file_processor_header(tmp_path):
128-
fn = tmp_path / 'empty.xml'
129+
fn = tmp_path / f"{uuid.uuid4()}.xml"
129130
fn.write_text("""<?xml version='1.0' encoding='UTF-8'?>
130131
<osm version="0.6" generator="test-pyosmium" timestamp="2014-08-26T20:22:02Z">
131132
<bounds minlat="-90" minlon="-180" maxlat="90" maxlon="180"/>
@@ -234,7 +235,7 @@ def test_filtered_handler_basehandler(opl_buffer, tmp_path):
234235
r4
235236
""")
236237

237-
testf = tmp_path / 'test.opl'
238+
testf = tmp_path / f"{uuid.uuid4()}.opl"
238239

239240
with osmium.SimpleWriter(str(testf)) as writer:
240241
fp = osmium.FileProcessor(data)\

test/test_forward_reference_writer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#
55
# Copyright (C) 2025 Sarah Hoffmann <[email protected]> and others.
66
# For a full list of authors see the git log.
7+
import uuid
78
import pytest
89

910
import osmium
@@ -32,7 +33,7 @@ def __init__(self, nid):
3233

3334

3435
def test_simple_forward_no_back_reference(ref_file, tmp_path):
35-
outfile = str(tmp_path / 'test.osm')
36+
outfile = tmp_path / f"{uuid.uuid4()}.osm"
3637

3738
with osmium.ForwardReferenceWriter(outfile, ref_file, back_references=False) as writer:
3839
writer.add_node(DummyNode(2))
@@ -47,7 +48,7 @@ def test_simple_forward_no_back_reference(ref_file, tmp_path):
4748

4849

4950
def test_simple_forward_with_back_reference(ref_file, tmp_path):
50-
outfile = str(tmp_path / 'test.osm')
51+
outfile = str(tmp_path / f"{uuid.uuid4()}.osm")
5152

5253
with osmium.ForwardReferenceWriter(outfile, ref_file) as writer:
5354
writer.add_node(DummyNode(2))

test/test_geom.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@
77
import json
88

99
import pytest
10-
11-
import osmium
1210
import osmium.geom
1311

14-
wkbfab = osmium.geom.WKBFactory()
15-
1612

1713
@pytest.fixture
1814
def node_geom(test_data):

test/test_id_tracker.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Copyright (C) 2025 Sarah Hoffmann <[email protected]> and others.
66
# For a full list of authors see the git log.
77
import pytest
8+
import uuid
89

910
import osmium
1011

@@ -169,7 +170,7 @@ def test_complete_backward_references(tmp_path, depth):
169170
if depth == 0:
170171
data_file = osmium.io.FileBuffer(REF_SRC.encode('utf-8'), 'opl')
171172
else:
172-
data_file = tmp_path / 'test.opl'
173+
data_file = tmp_path / f"{uuid.uuid4()}.opl"
173174
data_file.write_text(REF_SRC)
174175

175176
ids = osmium.IdTracker()
@@ -191,7 +192,7 @@ def test_complete_forward_references(tmp_path, depth):
191192
if depth == 0:
192193
data_file = osmium.io.FileBuffer(REF_SRC.encode('utf-8'), 'opl')
193194
else:
194-
data_file = tmp_path / 'test.opl'
195+
data_file = tmp_path / f"{uuid.uuid4()}.opl"
195196
data_file.write_text(REF_SRC)
196197

197198
ids = osmium.IdTracker()

0 commit comments

Comments
 (0)