From 77833ece3b6db2c7b3f2e33a9b8da3f9fd9b990b Mon Sep 17 00:00:00 2001 From: Brett Landau Date: Wed, 31 Jul 2019 16:28:43 -0700 Subject: Fix test execution bugs in proctor-go and proctor-python. proctor-go had a bug where it would incorrectly identify a tool test as a disk test. Instead of searching for the test on disk as the identification method, we now check if the test name ends in ".go". If the test ends in ".go" it is run as a disk test, otherwise the test is run as a tool test. Python tests need to be run from within the directory they exist. Functionality to split the test name from it's parent directory has been added and a cmd.Dir argument has been set. PiperOrigin-RevId: 261021693 --- test/runtimes/python/proctor-python.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'test/runtimes/python') diff --git a/test/runtimes/python/proctor-python.go b/test/runtimes/python/proctor-python.go index 3f83f3d70..816b1f44a 100644 --- a/test/runtimes/python/proctor-python.go +++ b/test/runtimes/python/proctor-python.go @@ -28,6 +28,7 @@ import ( var ( dir = os.Getenv("LANG_DIR") + testDir = filepath.Join(dir, "Lib", "test") testRegEx = regexp.MustCompile(`^test_.+\.py$`) ) @@ -42,16 +43,15 @@ func main() { func (p pythonRunner) ListTests() ([]string, error) { var testSlice []string - root := filepath.Join(dir, "Lib/test") - err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { + err := filepath.Walk(testDir, func(path string, info os.FileInfo, err error) error { name := filepath.Base(path) if info.IsDir() || !testRegEx.MatchString(name) { return nil } - relPath, err := filepath.Rel(root, path) + relPath, err := filepath.Rel(testDir, path) if err != nil { return err } @@ -60,15 +60,19 @@ func (p pythonRunner) ListTests() ([]string, error) { }) if err != nil { - return nil, fmt.Errorf("walking %q: %v", root, err) + return nil, fmt.Errorf("walking %q: %v", testDir, err) } return testSlice, nil } func (p pythonRunner) RunTest(test string) error { - args := []string{"-m", "test", test} + // Python tests need to be run in the directory in which they exist. + // Split the filename from it's directory and execute in the correct directory. + relDir, file := filepath.Split(test) + args := []string{"-m", "test", file} cmd := exec.Command(filepath.Join(dir, "python"), args...) + cmd.Dir = filepath.Join(testDir, relDir) cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr if err := cmd.Run(); err != nil { return fmt.Errorf("failed to run: %v", err) -- cgit v1.2.3