Skip to content

Commit f67eb6f

Browse files
guilhermeleobaspytorchmergebot
authored andcommitted
Fix path matching in CPythonTestCase/setUpClass (pytorch#153070)
Pull Request resolved: pytorch#153070 Approved by: https://github.com/amjames, https://github.com/anijain2305, https://github.com/Skylion007
1 parent c5ebc12 commit f67eb6f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

torch/_dynamo/test_case.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import inspect
1616
import logging
1717
import os
18-
import pathlib
1918
import re
2019
import sys
2120
import unittest
@@ -178,13 +177,14 @@ def tearDownClass(cls) -> None:
178177
@classmethod
179178
def setUpClass(cls) -> None:
180179
# Skip test if python versions doesn't match
181-
normalized_path = pathlib.PurePath("dynamo/cpython").as_posix()
182-
regex = re.escape(normalized_path) + r"\b\d+_\d{2}\b"
183-
m = re.search(regex, inspect.getfile(cls))
180+
prefix = os.path.join("dynamo", "cpython") + os.path.sep
181+
regex = re.escape(prefix) + r"\d_\d{2}"
182+
search_path = inspect.getfile(cls)
183+
m = re.search(regex, search_path)
184184
if m:
185-
test_py_ver = tuple(map(int, m.group().split("_")))
185+
test_py_ver = tuple(map(int, m.group().removeprefix(prefix).split("_")))
186186
py_ver = sys.version_info[:2]
187-
if py_ver != test_py_ver:
187+
if py_ver < test_py_ver:
188188
expected = ".".join(map(str, test_py_ver))
189189
got = ".".join(map(str, py_ver))
190190
raise unittest.SkipTest(

0 commit comments

Comments
 (0)