Skip to content

Commit 6c26ad1

Browse files
committed
resolve paths in test
1 parent 59a2b65 commit 6c26ad1

File tree

1 file changed

+30
-42
lines changed

1 file changed

+30
-42
lines changed

tests/test_unit_test_discovery.py

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def test_discover_tests_pytest_with_temp_dir_root():
133133
assert len(discovered_tests) == 1
134134
assert len(discovered_tests["dummy_code.dummy_function"]) == 2
135135
dummy_tests = discovered_tests["dummy_code.dummy_function"]
136-
assert all(test.tests_in_file.test_file == test_file_path for test in dummy_tests)
136+
assert all(test.tests_in_file.test_file.resolve() == test_file_path.resolve() for test in dummy_tests)
137137
assert {test.tests_in_file.test_function for test in dummy_tests} == {
138138
"test_dummy_parametrized_function[True]",
139139
"test_dummy_function",
@@ -204,16 +204,13 @@ def test_discover_tests_pytest_with_multi_level_dirs():
204204

205205
# Check if the test files at all levels are discovered
206206
assert len(discovered_tests) == 3
207-
assert next(iter(discovered_tests["root_code.root_function"])).tests_in_file.test_file == root_test_file_path
208-
assert (
209-
next(iter(discovered_tests["level1.level1_code.level1_function"])).tests_in_file.test_file
210-
== level1_test_file_path
211-
)
207+
discovered_root_test = next(iter(discovered_tests["root_code.root_function"])).tests_in_file.test_file
208+
assert discovered_root_test.resolve() == root_test_file_path.resolve()
209+
discovered_level1_test = next(iter(discovered_tests["level1.level1_code.level1_function"])).tests_in_file.test_file
210+
assert discovered_level1_test.resolve() == level1_test_file_path.resolve()
212211

213-
assert (
214-
next(iter(discovered_tests["level1.level2.level2_code.level2_function"])).tests_in_file.test_file
215-
== level2_test_file_path
216-
)
212+
discovered_level2_test = next(iter(discovered_tests["level1.level2.level2_code.level2_function"])).tests_in_file.test_file
213+
assert discovered_level2_test.resolve() == level2_test_file_path.resolve()
217214

218215

219216
def test_discover_tests_pytest_dirs():
@@ -295,20 +292,15 @@ def test_discover_tests_pytest_dirs():
295292

296293
# Check if the test files at all levels are discovered
297294
assert len(discovered_tests) == 4
298-
assert next(iter(discovered_tests["root_code.root_function"])).tests_in_file.test_file == root_test_file_path
299-
assert (
300-
next(iter(discovered_tests["level1.level1_code.level1_function"])).tests_in_file.test_file
301-
== level1_test_file_path
302-
)
303-
assert (
304-
next(iter(discovered_tests["level1.level2.level2_code.level2_function"])).tests_in_file.test_file
305-
== level2_test_file_path
306-
)
295+
discovered_root_test = next(iter(discovered_tests["root_code.root_function"])).tests_in_file.test_file
296+
assert discovered_root_test.resolve() == root_test_file_path.resolve()
297+
discovered_level1_test = next(iter(discovered_tests["level1.level1_code.level1_function"])).tests_in_file.test_file
298+
assert discovered_level1_test.resolve() == level1_test_file_path.resolve()
299+
discovered_level2_test = next(iter(discovered_tests["level1.level2.level2_code.level2_function"])).tests_in_file.test_file
300+
assert discovered_level2_test.resolve() == level2_test_file_path.resolve()
307301

308-
assert (
309-
next(iter(discovered_tests["level1.level3.level3_code.level3_function"])).tests_in_file.test_file
310-
== level3_test_file_path
311-
)
302+
discovered_level3_test = next(iter(discovered_tests["level1.level3.level3_code.level3_function"])).tests_in_file.test_file
303+
assert discovered_level3_test.resolve() == level3_test_file_path.resolve()
312304

313305

314306
def test_discover_tests_pytest_with_class():
@@ -342,10 +334,8 @@ def test_discover_tests_pytest_with_class():
342334

343335
# Check if the test class and method are discovered
344336
assert len(discovered_tests) == 1
345-
assert (
346-
next(iter(discovered_tests["some_class_code.SomeClass.some_method"])).tests_in_file.test_file
347-
== test_file_path
348-
)
337+
discovered_class_test = next(iter(discovered_tests["some_class_code.SomeClass.some_method"])).tests_in_file.test_file
338+
assert discovered_class_test.resolve() == test_file_path.resolve()
349339

350340

351341
def test_discover_tests_pytest_with_double_nested_directories():
@@ -383,12 +373,10 @@ def test_discover_tests_pytest_with_double_nested_directories():
383373

384374
# Check if the test class and method are discovered
385375
assert len(discovered_tests) == 1
386-
assert (
387-
next(
388-
iter(discovered_tests["nested.more_nested.nested_class_code.NestedClass.nested_method"])
389-
).tests_in_file.test_file
390-
== test_file_path
391-
)
376+
discovered_nested_test = next(
377+
iter(discovered_tests["nested.more_nested.nested_class_code.NestedClass.nested_method"])
378+
).tests_in_file.test_file
379+
assert discovered_nested_test.resolve() == test_file_path.resolve()
392380

393381

394382
def test_discover_tests_with_code_in_dir_and_test_in_subdir():
@@ -433,7 +421,8 @@ def test_discover_tests_with_code_in_dir_and_test_in_subdir():
433421

434422
# Check if the test file is discovered and associated with the code file
435423
assert len(discovered_tests) == 1
436-
assert next(iter(discovered_tests["code.some_code.some_function"])).tests_in_file.test_file == test_file_path
424+
discovered_test_file = next(iter(discovered_tests["code.some_code.some_function"])).tests_in_file.test_file
425+
assert discovered_test_file.resolve() == test_file_path.resolve()
437426

438427

439428
def test_discover_tests_pytest_with_nested_class():
@@ -469,10 +458,8 @@ def test_discover_tests_pytest_with_nested_class():
469458

470459
# Check if the test for the nested class method is discovered
471460
assert len(discovered_tests) == 1
472-
assert (
473-
next(iter(discovered_tests["nested_class_code.OuterClass.InnerClass.inner_method"])).tests_in_file.test_file
474-
== test_file_path
475-
)
461+
discovered_inner_test = next(iter(discovered_tests["nested_class_code.OuterClass.InnerClass.inner_method"])).tests_in_file.test_file
462+
assert discovered_inner_test.resolve() == test_file_path.resolve()
476463

477464

478465
def test_discover_tests_pytest_separate_moduledir():
@@ -509,7 +496,8 @@ def test_discover_tests_pytest_separate_moduledir():
509496

510497
# Check if the test for the nested class method is discovered
511498
assert len(discovered_tests) == 1
512-
assert next(iter(discovered_tests["mypackage.code.find_common_tags"])).tests_in_file.test_file == test_file_path
499+
discovered_test_file = next(iter(discovered_tests["mypackage.code.find_common_tags"])).tests_in_file.test_file
500+
assert discovered_test_file.resolve() == test_file_path.resolve()
513501

514502

515503
def test_unittest_discovery_with_pytest():
@@ -554,7 +542,7 @@ def test_add(self):
554542
assert "calculator.Calculator.add" in discovered_tests
555543
assert len(discovered_tests["calculator.Calculator.add"]) == 1
556544
calculator_test = next(iter(discovered_tests["calculator.Calculator.add"]))
557-
assert calculator_test.tests_in_file.test_file == test_file_path
545+
assert calculator_test.tests_in_file.test_file.resolve() == test_file_path.resolve()
558546
assert calculator_test.tests_in_file.test_function == "test_add"
559547

560548

@@ -622,7 +610,7 @@ def test_add(self):
622610
assert "calculator.Calculator.add" in discovered_tests
623611
assert len(discovered_tests["calculator.Calculator.add"]) == 1
624612
calculator_test = next(iter(discovered_tests["calculator.Calculator.add"]))
625-
assert calculator_test.tests_in_file.test_file == test_file_path
613+
assert calculator_test.tests_in_file.test_file.resolve() == test_file_path.resolve()
626614
assert calculator_test.tests_in_file.test_function == "test_add"
627615

628616

@@ -720,7 +708,7 @@ def test_add_with_parameters(self):
720708
assert "calculator.Calculator.add" in discovered_tests
721709
assert len(discovered_tests["calculator.Calculator.add"]) == 1
722710
calculator_test = next(iter(discovered_tests["calculator.Calculator.add"]))
723-
assert calculator_test.tests_in_file.test_file == test_file_path
711+
assert calculator_test.tests_in_file.test_file.resolve() == test_file_path.resolve()
724712
assert calculator_test.tests_in_file.test_function == "test_add_with_parameters"
725713

726714

0 commit comments

Comments
 (0)