Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing enivronment to Python2.7 cannot find test. #16962

Closed
ttSpace opened this issue Aug 13, 2021 · 1 comment · Fixed by #16967
Closed

Changing enivronment to Python2.7 cannot find test. #16962

ttSpace opened this issue Aug 13, 2021 · 1 comment · Fixed by #16967
Labels
area-testing bug Issue identified by VS Code Team member as probable bug on-testplan Added to test plan regression Bug didn't exist in a previous release
Milestone

Comments

@ttSpace
Copy link

ttSpace commented Aug 13, 2021

Environment data

Version: 1.60.0-insider (user setup)
Commit: 699084fdb48460c68086b85b5c08f3d39055e772
Date: 2021-08-12T19:13:28.730Z
Electron: 13.1.8
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Windows_NT x64 10.0.17134

Build of python-insider: 2021.9.1125171759-dev
Build of jupyter-insider: 2021.8.2025984474

Expected behaviour

Tests are discovered.

Actual behaviour

Change enivronment to Python2.7. Test Discovery Failed with no error message. I try to Click "Enable and configure a test framework" -> Select "Unittest" and next ". Root directory" -> Select first test file name format *test.py. Nothing happened.
By the way, changing enivronment to Anaconda can find tests successfully.

image

Steps to reproduce:

  1. Input below code:
import unittest
class PassingTests(unittest.TestCase):
    def test_passing(self):
        self.assertEqual(42, 42)
    def test_passing_still(self):
        self.assertEqual("silly walk", "silly walk")
class FailingTests(unittest.TestCase):
    def test_failure(self):
        self.assertEqual(42, -13)
    def test_failure_still(self):
        self.assertEqual("I'm right!", "no, I am!")
  1. Run tests with unittest framework.
 "python.testing.unittestEnabled": true
  1. Run command: "Run All Tests".
  2. Change enivronment to Python2.7.

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

User belongs to experiment group 'pythonaa'
User belongs to experiment group 'pythonJediLSP'
User belongs to experiment group 'pythonDiscoveryModuleWithoutWatcher'
User belongs to experiment group 'pythonTensorboardExperiment'
User belongs to experiment group 'PythonPyTorchProfiler'
User belongs to experiment group 'pythonDeprecatePythonPath'
User belongs to experiment group 'pythonSortEnvs'
Python interpreter path: C:\Python39-64\python.exe
Starting Pylance language server.
Error 2021-08-13 06:45:27: Failed to check if file needs to be fixed [EntryNotFound (FileSystemError): Unable to read file 'c:\Users\vting\AppData\Roaming\Code - Insiders\User\settings.json' (Error: Unable to resolve non-existing file 'c:\Users\vting\AppData\Roaming\Code - Insiders\User\settings.json')
	at _handleError (c:\Users\vting\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:85:159261)
	at processTicksAndRejections (internal/process/task_queues.js:93:5)
	at async y.readText (c:\Users\vting\.vscode-insiders\extensions\ms-python.python-2021.9.1125171759-dev\out\client\extension.js:9:338733)
	at async p.doesFileNeedToBeFixed (c:\Users\vting\.vscode-insiders\extensions\ms-python.python-2021.9.1125171759-dev\out\client\extension.js:59:559685)
	at async c:\Users\vting\.vscode-insiders\extensions\ms-python.python-2021.9.1125171759-dev\out\client\extension.js:59:558812
	at async Promise.all (index 0)
	at async p.getFilesToBeFixed (c:\Users\vting\.vscode-insiders\extensions\ms-python.python-2021.9.1125171759-dev\out\client\extension.js:59:558758)
	at async p.updateTestSettings (c:\Users\vting\.vscode-insiders\extensions\ms-python.python-2021.9.1125171759-dev\out\client\extension.js:59:558385)] {
  code: 'FileNotFound'
}
> C:\Python39-64\python.exe -c "
import unittest
import inspect

def get_sourceline(obj):
    s, n = inspect.getsourcelines(obj)
    for i, v in enumerate(s):
        if v.strip().startswith('def'):
            return str(n+i)
    return '*'

def generate_test_cases(suite):
    for test in suite:
        if isinstance(test, unittest.TestCase):
            yield test
        else:
            yield from generate_test_cases(test)

loader = unittest.TestLoader()
suite = loader.discover(".", pattern="*test.py")

print("start")  # Don't remove this line
loader_errors = []
for s in generate_test_cases(suite):
    tm = getattr(s, s._testMethodName)
    testId = s.id()
    if testId.startswith("unittest.loader._FailedTest"):
        loader_errors.append(s._exception)
    else:
        print(testId.replace(".", ":") + ":" + get_sourceline(tm))

for error in loader_errors:
    try:
        print("=== exception start ===")
        print(error.msg)
        print("=== exception end ===")
    except:
        pass
"
cwd: c:\Users\vting\Downloads\Test2
> C:\Python39-64\python.exe -c "
import unittest
import inspect

def get_sourceline(obj):
    s, n = inspect.getsourcelines(obj)
    for i, v in enumerate(s):
        if v.strip().startswith('def'):
            return str(n+i)
    return '*'

def generate_test_cases(suite):
    for test in suite:
        if isinstance(test, unittest.TestCase):
            yield test
        else:
            yield from generate_test_cases(test)

loader = unittest.TestLoader()
suite = loader.discover(".", pattern="*test.py")

print("start")  # Don't remove this line
loader_errors = []
for s in generate_test_cases(suite):
    tm = getattr(s, s._testMethodName)
    testId = s.id()
    if testId.startswith("unittest.loader._FailedTest"):
        loader_errors.append(s._exception)
    else:
        print(testId.replace(".", ":") + ":" + get_sourceline(tm))

for error in loader_errors:
    try:
        print("=== exception start ===")
        print(error.msg)
        print("=== exception end ===")
    except:
        pass
"
cwd: c:\Users\vting\Downloads\Test2
Python interpreter path: C:\ProgramData\Anaconda3\python.exe
> C:\ProgramData\Anaconda3\python.exe -c "
import unittest
import inspect

def get_sourceline(obj):
    s, n = inspect.getsourcelines(obj)
    for i, v in enumerate(s):
        if v.strip().startswith('def'):
            return str(n+i)
    return '*'

def generate_test_cases(suite):
    for test in suite:
        if isinstance(test, unittest.TestCase):
            yield test
        else:
            yield from generate_test_cases(test)

loader = unittest.TestLoader()
suite = loader.discover(".", pattern="*test.py")

print("start")  # Don't remove this line
loader_errors = []
for s in generate_test_cases(suite):
    tm = getattr(s, s._testMethodName)
    testId = s.id()
    if testId.startswith("unittest.loader._FailedTest"):
        loader_errors.append(s._exception)
    else:
        print(testId.replace(".", ":") + ":" + get_sourceline(tm))

for error in loader_errors:
    try:
        print("=== exception start ===")
        print(error.msg)
        print("=== exception end ===")
    except:
        pass
"
cwd: c:\Users\vting\Downloads\Test2
Python interpreter path: C:\Python27-64\python.exe
> C:\Python27-64\python.exe -c "
import unittest
import inspect

def get_sourceline(obj):
    s, n = inspect.getsourcelines(obj)
    for i, v in enumerate(s):
        if v.strip().startswith('def'):
            return str(n+i)
    return '*'

def generate_test_cases(suite):
    for test in suite:
        if isinstance(test, unittest.TestCase):
            yield test
        else:
            yield from generate_test_cases(test)

loader = unittest.TestLoader()
suite = loader.discover(".", pattern="*test.py")

print("start")  # Don't remove this line
loader_errors = []
for s in generate_test_cases(suite):
    tm = getattr(s, s._testMethodName)
    testId = s.id()
    if testId.startswith("unittest.loader._FailedTest"):
        loader_errors.append(s._exception)
    else:
        print(testId.replace(".", ":") + ":" + get_sourceline(tm))

for error in loader_errors:
    try:
        print("=== exception start ===")
        print(error.msg)
        print("=== exception end ===")
    except:
        pass
"
cwd: c:\Users\vting\Downloads\Test2
> C:\Python27-64\python.exe -c "
import unittest
import inspect

def get_sourceline(obj):
    s, n = inspect.getsourcelines(obj)
    for i, v in enumerate(s):
        if v.strip().startswith('def'):
            return str(n+i)
    return '*'

def generate_test_cases(suite):
    for test in suite:
        if isinstance(test, unittest.TestCase):
            yield test
        else:
            yield from generate_test_cases(test)

loader = unittest.TestLoader()
suite = loader.discover(".", pattern="*test.py")

print("start")  # Don't remove this line
loader_errors = []
for s in generate_test_cases(suite):
    tm = getattr(s, s._testMethodName)
    testId = s.id()
    if testId.startswith("unittest.loader._FailedTest"):
        loader_errors.append(s._exception)
    else:
        print(testId.replace(".", ":") + ":" + get_sourceline(tm))

for error in loader_errors:
    try:
        print("=== exception start ===")
        print(error.msg)
        print("=== exception end ===")
    except:
        pass
"
cwd: c:\Users\vting\Downloads\Test2
> C:\Python27-64\python.exe -c "
import unittest
import inspect

def get_sourceline(obj):
    s, n = inspect.getsourcelines(obj)
    for i, v in enumerate(s):
        if v.strip().startswith('def'):
            return str(n+i)
    return '*'

def generate_test_cases(suite):
    for test in suite:
        if isinstance(test, unittest.TestCase):
            yield test
        else:
            yield from generate_test_cases(test)

loader = unittest.TestLoader()
suite = loader.discover(".", pattern="*test.py")

print("start")  # Don't remove this line
loader_errors = []
for s in generate_test_cases(suite):
    tm = getattr(s, s._testMethodName)
    testId = s.id()
    if testId.startswith("unittest.loader._FailedTest"):
        loader_errors.append(s._exception)
    else:
        print(testId.replace(".", ":") + ":" + get_sourceline(tm))

for error in loader_errors:
    try:
        print("=== exception start ===")
        print(error.msg)
        print("=== exception end ===")
    except:
        pass
"
cwd: c:\Users\vting\Downloads\Test2
> C:\Python27-64\python.exe -c "
import unittest
import inspect

def get_sourceline(obj):
    s, n = inspect.getsourcelines(obj)
    for i, v in enumerate(s):
        if v.strip().startswith('def'):
            return str(n+i)
    return '*'

def generate_test_cases(suite):
    for test in suite:
        if isinstance(test, unittest.TestCase):
            yield test
        else:
            yield from generate_test_cases(test)

loader = unittest.TestLoader()
suite = loader.discover(".", pattern="*test.py")

print("start")  # Don't remove this line
loader_errors = []
for s in generate_test_cases(suite):
    tm = getattr(s, s._testMethodName)
    testId = s.id()
    if testId.startswith("unittest.loader._FailedTest"):
        loader_errors.append(s._exception)
    else:
        print(testId.replace(".", ":") + ":" + get_sourceline(tm))

for error in loader_errors:
    try:
        print("=== exception start ===")
        print(error.msg)
        print("=== exception end ===")
    except:
        pass
"
cwd: c:\Users\vting\Downloads\Test2

@ttSpace ttSpace added the triage-needed Needs assignment to the proper sub-team label Aug 13, 2021
@karthiknadig karthiknadig added area-testing needs PR regression Bug didn't exist in a previous release bug Issue identified by VS Code Team member as probable bug and removed triage-needed Needs assignment to the proper sub-team labels Aug 13, 2021
@karthiknadig karthiknadig added this to the August 2021 milestone Aug 13, 2021
@karthiknadig
Copy link
Member

Thanks for the report. I was able to repro this.

@karthiknadig karthiknadig added the verification-steps-needed Steps to verify are needed for verification label Aug 19, 2021
@karthiknadig karthiknadig self-assigned this Aug 19, 2021
@karthiknadig karthiknadig added the verification-needed Verification of issue is requested label Aug 20, 2021
@karthiknadig karthiknadig added on-testplan Added to test plan and removed verification-steps-needed Steps to verify are needed for verification verification-needed Verification of issue is requested labels Aug 20, 2021
@karthiknadig karthiknadig removed their assignment Aug 20, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-testing bug Issue identified by VS Code Team member as probable bug on-testplan Added to test plan regression Bug didn't exist in a previous release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants