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

PyTest fails to discover tests with imports which print output #7574

Closed
AndrewLister-STFC opened this issue Sep 24, 2019 · 3 comments
Closed
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@AndrewLister-STFC
Copy link

AndrewLister-STFC commented Sep 24, 2019

Environment data

  • VS Code version: 1.38.1
  • Extension version (available under the Extensions sidebar): 2019.9.34911
  • OS and version: Windows10 1803 (remote dev on Ubuntu 18.04.3)
  • Python version (& distribution if applicable, e.g. Anaconda): 2.7.15
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
  • Relevant/affected Python packages and their versions: N/A (editted as found a minimal working example)
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info How to update the language server to the latest stable version #3977): Jedi

Expected behaviour

PyTest should detect all available tests provided they match the requirements on naming conventions.

Actual behaviour

PyTest returns the error:

Test Discovery failed: 
SyntaxError: Unexpected token F in JSON at position 0

This seems to be due to the discovery reading from stdout, as it picks up the first letter of a message that is printed from within a python import, and therefore cannot parse it as JSON.
I think this is only an issue with prints occuring from sources external to python.

Steps to reproduce:

  1. Create a minimal working example as follows:
    2 directories: "some_module", "tests"
"some_module" directory: "__init__.py", "funcs.py", "run_me.bat"

"__init__.py" : empty
"funcs.py" :

import os
def do_thing():
    pass
os.system(os.path.join(os.path.dirname(__file__), 'run_me.bat'))

"run_me.bat" :

ECHO hello world
"tests" directory: "__init__.py", "test_imports.py"

"__init__.py" : empty
"test_imports.py" :

import sys, os
sys.path.append(os.path.join(__file__, os.pardir, os.pardir))
from unittest import TestCase
from some_module import funcs
class Tester(TestCase):
    def test_import(self):
        pass
  1. Now go to python.settings and check that pytest is being used
  2. Check that the test appears in the "TEST: PYTHON" panel

Logs

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

Python

/usr/bin/python ~/.vscode-server/extensions/ms-python.python-2019.9.34911/pythonFiles/testing_tools/run_adapter.py discover pytest -- -s --cache-clear

Python Test Log

python /home/eel23943/.vscode-server/extensions/ms-python.python-2019.9.34911/pythonFiles/testing_tools/run_adapter.py discover pytest -- -s --cache-clear
Test Discovery failed: 
SyntaxError: Unexpected token F in JSON at position 0

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)

Error Python Extension: 2019-09-24 09:16:31: Failed to parse discovered Test [Error: FrameworkManager-[Notice] Welcome to Mantid 4.1.0FrameworkManager-[Notice] Please cite: http://dx.doi.org/10.1016/j.nima.2014.07.029 and this release: http://dx.doi.org/10.5286/Software/Mantid4.1DownloadInstrument-[Notice] All instrument definitions up to date[{"rootid": ".", "tests": [{"source":  ...

Note: The rest of this message looks to be the correct format, but its very long so I'm only posting the start.

@AndrewLister-STFC AndrewLister-STFC added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Sep 24, 2019
@karrtikr
Copy link

Closing as dup of #6594

@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Sep 24, 2019
@AndrewLister-STFC
Copy link
Author

Closing as dup of #6594

Sorry, I hadn't spotted that one

@karrtikr
Copy link

Not a problem, thanks for reporting!

@lock lock bot locked as resolved and limited conversation to collaborators Oct 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

2 participants