1818from libei ._capi .loader import LazyLibrary , LibraryNotFoundError
1919
2020_found_libc = util .find_library ("c" )
21- if _found_libc is None :
22- raise RuntimeError ("no C library found -- these tests need one to stand in" )
23- _LIBC : str = _found_libc
21+ _LIBC : str = _found_libc or ""
22+ # A skip, not a module-level raise: raising here was a *collection* error, so
23+ # on a machine with no findable C library (Windows) pytest ran none of the
24+ # suite's other tests either. Only the tests that load a real library need
25+ # one; the loader-defers tests below run everywhere.
26+ _needs_libc = pytest .mark .skipif (
27+ _found_libc is None , reason = "needs a real C library as a stand-in (POSIX only)"
28+ )
2429
2530
2631def test_import_does_not_touch_the_filesystem () -> None :
@@ -43,11 +48,13 @@ def test_missing_library_is_not_available() -> None:
4348 assert lib .is_available () is False
4449
4550
51+ @_needs_libc
4652def test_real_library_is_available () -> None :
4753 lib = LazyLibrary (_LIBC )
4854 assert lib .is_available () is True
4955
5056
57+ @_needs_libc
5158def test_real_function_call_round_trips () -> None :
5259 lib = LazyLibrary (_LIBC )
5360 abs_ = lib .function ("abs" , (c_int ,), c_int )
@@ -67,13 +74,15 @@ def test_function_result_is_cached_across_calls() -> None:
6774 abs_ (- 1 )
6875
6976
77+ @_needs_libc
7078def test_missing_symbol_raises_library_not_found_error () -> None :
7179 lib = LazyLibrary (_LIBC )
7280 nonexistent = lib .function ("this_symbol_does_not_exist_in_libc" , (c_char_p ,), c_int )
7381 with pytest .raises (LibraryNotFoundError , match = "does not export" ):
7482 nonexistent (b"x" )
7583
7684
85+ @_needs_libc
7786def test_two_lazy_libraries_are_independent () -> None :
7887 good = LazyLibrary (_LIBC )
7988 bad = LazyLibrary ("this-library-definitely-does-not-exist.so.999" )
0 commit comments