@@ -27,7 +27,6 @@ public void Dispose()
2727
2828 static IEnumerable < string [ ] > MyTestCases ( )
2929 {
30- yield return new [ ] { "test_enum" , "test_enum_standard_attrs" } ;
3130 yield return new [ ] { "test_generic" , "test_missing_generic_type" } ;
3231 }
3332
@@ -44,18 +43,21 @@ public void EmbeddedPythonTest(string testFile, string testName)
4443 string path = Path . Combine ( folder , testFile + ".py" ) ;
4544 if ( ! File . Exists ( path ) ) throw new FileNotFoundException ( "Cannot find test file" , path ) ;
4645
47- // importlib gives more helpful error messages than 'import'
46+ // We could use 'import' below, but importlib gives more helpful error messages than 'import'
4847 // https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly
48+ // Sometimes sys.path does not contain the site-packages directory, so we add it explicitly
49+ // Because the Python tests sometimes have relative imports, the module name must be inside the tests package
4950 PythonEngine . Exec ( $@ "
5051import sys
5152import os
52- fixtures_path = os.path.join(r'{ folder } ', 'fixtures')
53- sys.path.append(fixtures_path)
53+ libdir = os.path.dirname(sys.modules['os'].__file__)
54+ sys.path.append(os.path.join(libdir, 'site-packages'))
55+ sys.path.append(os.path.dirname(r'{ folder } '))
56+ sys.path.append(os.path.join(r'{ folder } ', 'fixtures'))
5457import clr
5558clr.AddReference('Python.Test')
56- sys.path.append(r'{ folder } ')
57- import utils
58- module_name = '{ testFile } '
59+ import tests
60+ module_name = 'tests.{ testFile } '
5961file_path = r'{ path } '
6062import importlib.util
6163spec = importlib.util.spec_from_file_location(module_name, file_path)
0 commit comments