From bec977ea15fac262c113e1ef950c2f4f7927156c Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Fri, 10 Sep 2021 09:32:38 -0700 Subject: [PATCH 1/4] Fix for ModuleNotFoundError --- pythonFiles/testing_tools/unittest_discovery.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pythonFiles/testing_tools/unittest_discovery.py b/pythonFiles/testing_tools/unittest_discovery.py index 6e02f53d240a..cd2270ee5a83 100644 --- a/pythonFiles/testing_tools/unittest_discovery.py +++ b/pythonFiles/testing_tools/unittest_discovery.py @@ -5,7 +5,7 @@ start_dir = sys.argv[1] pattern = sys.argv[2] - +sys.path.insert(0,'') def get_sourceline(obj): try: From de0b3da34589ef404b5c8b31bcf2dc603684e2e6 Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Fri, 10 Sep 2021 09:33:37 -0700 Subject: [PATCH 2/4] Add news --- news/2 Fixes/17363.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/2 Fixes/17363.md diff --git a/news/2 Fixes/17363.md b/news/2 Fixes/17363.md new file mode 100644 index 000000000000..9392ef1387b4 --- /dev/null +++ b/news/2 Fixes/17363.md @@ -0,0 +1 @@ +Fix for `unittest` ModuleNotFoundError when discovering tests. From 2e57cedb48e92794d7c21a4b06d7a5bbe3a64e13 Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Fri, 10 Sep 2021 11:42:48 -0700 Subject: [PATCH 3/4] Ensure we use cwd --- pythonFiles/testing_tools/unittest_discovery.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pythonFiles/testing_tools/unittest_discovery.py b/pythonFiles/testing_tools/unittest_discovery.py index cd2270ee5a83..11fa26dcc310 100644 --- a/pythonFiles/testing_tools/unittest_discovery.py +++ b/pythonFiles/testing_tools/unittest_discovery.py @@ -1,11 +1,12 @@ import unittest import inspect +import os import sys import traceback start_dir = sys.argv[1] pattern = sys.argv[2] -sys.path.insert(0,'') +sys.path.insert(0, os.getcwd()) def get_sourceline(obj): try: From 6f90f99714cb77e8ab9669c17159ca6782213105 Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Fri, 10 Sep 2021 12:13:15 -0700 Subject: [PATCH 4/4] linting --- pythonFiles/testing_tools/unittest_discovery.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pythonFiles/testing_tools/unittest_discovery.py b/pythonFiles/testing_tools/unittest_discovery.py index 11fa26dcc310..d13ea1c10dd9 100644 --- a/pythonFiles/testing_tools/unittest_discovery.py +++ b/pythonFiles/testing_tools/unittest_discovery.py @@ -8,6 +8,7 @@ pattern = sys.argv[2] sys.path.insert(0, os.getcwd()) + def get_sourceline(obj): try: s, n = inspect.getsourcelines(obj)