Code gives me the following errors when pytest performs test discovery. I'm using a virtual environment (Pipenv) and have the environment activated in vscode. The error occurred some time after i upgraded to vscode Juli version 2020. I have tried removing and purging code with dpkg, and deleted the extensions located in ~/.vscode/extensions. After that, I installed the June version where i previously had no errors, but the error still occurs.
Python test log:
python /home/christian/.vscode/extensions/ms-python.python-2020.8.101144/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /home/christian/Documents/source/personalprojects/portfolioapp/services/activity-service -s --cache-clear tests
Test Discovery failed:
SyntaxError: Unexpected end of JSON input
Python log:
> ~/.local/share/virtualenvs/activity-service-aBZdkeOh/bin/python ~/.vscode/extensions/ms-python.python-2020.8.101144/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir ~/Documents/source/personalprojects/portfolioapp/services/activity-service -s --cache-clear tests
cwd: ~/Documents/source/personalprojects/portfolioapp/services/activity-service
Error 2020-08-16 17:51:49: Failed to parse discovered Test [SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at /home/christian/.vscode/extensions/ms-python.python-2020.8.101144/out/client/extension.js:39:327177
at f.exec (/home/christian/.vscode/extensions/ms-python.python-2020.8.101144/out/client/extension.js:48:935503)
at async f.discoverTests (/home/christian/.vscode/extensions/ms-python.python-2020.8.101144/out/client/extension.js:48:934976)] {
stdout: ''
}
Error 2020-08-16 17:51:49: Python Extension: displayDiscoverStatus [SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at /home/christian/.vscode/extensions/ms-python.python-2020.8.101144/out/client/extension.js:39:327177
at f.exec (/home/christian/.vscode/extensions/ms-python.python-2020.8.101144/out/client/extension.js:48:935503)
at async f.discoverTests (/home/christian/.vscode/extensions/ms-python.python-2020.8.101144/out/client/extension.js:48:934976)] {
stdout: ''
}
If I run pytest inside the virtual env, The test runs succesfully without errors - so it seems have something to do with the python extension.
Does anyone know how to fix this?
The error message indicates the output of the pytest discover test command is not conformed to JSON regulation.
And you said the pytest works well in the terminal. So could you run the command in the Python test log directly in the terminal, and to check the outputs of this command?
the command:
python /home/christian/.vscode/extensions/ms-python.python-2020.8.101144/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /home/christian/Documents/source/personalprojects/portfolioapp/services/activity-service -s --cache-clear tests
If the outputs of this command really does not comply with JSON regulation that means the problem was caused by the pytest package, you need to fix the pytest package you are using.
If the outputs comply with the JSON regulation that means the problem was caused by the Python extension or the VSCode, as you have deleted the extension be located at ~/.vscode/extensions and reinstall the VSCode but the error still exists, so could you delete the project cache which under: C:\Users[USERNAME]\AppData\Roaming\Code\User\workspaceStorage(in windows)?
Related
I have created a robot script and tried to run the scripts in parallel using "pabot" package. Im getting the below error message stating that no main.py in the installed package.
Steps that I followed which cause this error.
Installed pabaot using the below cmd:
pip install robotframework-pabot
Below is the command I used to execute scripts using pabot
C:\Users\Prakash\PycharmProjects\Prakash_RobotFramework\tests>python -m pabot .
Below is the error message I received while executing the cmd.
C:\Program Files\Python39\python.exe: No module named pabot.main; 'pabot' is a package and cannot be directly executed"
I have checked the pabot installed folder where main.py is not available.
Try the following:
*** Settings ***
Library pabot.pabotLib
Execution:
Split execution to suite filesĀ»
pabot --pabotlib [path to tests]
Split execution on test levelĀ»
pabot --pabotlib --testlevelsplit [path to tests]
Looks like there is a pabot and pabotlib class within pabot. Use the following command to call pabot class within the pabot module.
python -m pabot.pabot --testlevelsplit .
I have an M1 Mac and am running VS Code with the latest version of the Python extension installed. I have set up a new virtual environment for a specific project, which has an extensive set of pytest tests to run. I have enable pytest tests in VS Code, but it returns "Error discovering pytest tests" in the Testing pane.
It instructs me to "see Output > Python" for details, and here I find the following:
> ./venv/bin/python ~/.vscode/extensions/ms-python.python-2022.0.1814523869/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir . -s --cache-clear .
cwd: .
[ERROR 2022-2-2 22:11:27.708]: Error discovering pytest tests:
[SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at a.runTestDiscovery (/Users/xxx/.vscode/extensions/ms-python.python-2022.0.1814523869/out/client/extension.js:85:82555)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Promise.all (index 0)
at async E.refreshTestData (/Users/xxx/.vscode/extensions/ms-python.python-2022.0.1814523869/out/client/extension.js:85:94153)
at async v.refreshTestDataInternal (/Users/xxx/.vscode/extensions/ms-python.python-2022.0.1814523869/out/client/extension.js:85:85547)
at async Promise.all (index 0)
at async v.refreshTestDataInternal (/Users/xxx/.vscode/extensions/ms-python.python-2022.0.1814523869/out/client/extension.js:85:86200)] {
stdout: ''
}
When I run the command in my terminal, I get a segmentation fault:
zsh: segmentation fault ./venv/bin/python discover pytest -- --rootdir . -s --cache-clear .
I've searched for a solution for this but have yet to find anything that works. Has anyone ever had the same problem? And ideally been able to fix it?
I am trying to test views and models for Django REST API written in pycharm and have installed pytest for this. I have written some tests and when I wanted to start them I got the following error message:
ERROR: usage: _jb_pytest_runner.py [options] [file_or_dir] [file_or_dir] [...]
_jb_pytest_runner.py: error: unrecognized arguments: --cov=frontend --cov-report=html
I have then checked if I have installed pytest properly and it seems I have. I have both Python 2.7.16 as well as Python 3.9.6 installed but am using Python 3. Could this be a compatibility problem or is it something else?
I have tried starting the tests both through the terminal using py.test and just in the IDE itself. I keep getting this same error message.
I have tried the approach below:
py.test: error: unrecognized arguments: --cov=ner_brands --cov-report=term-missing --cov-config
yet I seem to get the same error.
ERROR: usage: _jb_pytest_runner.py [options] [file_or_dir] [file_or_dir] [...]
_jb_pytest_runner.py: error: unrecognized arguments: --cov=frontend --cov-report=html
Does anyone know how I could solve this issue?
Thanks in advance.
First of all, yes, Python 3.9.6 is compatible with pytest 6.2.5, however, you appear to be missing a few dependencies. pytest is one of many different Python packages, and you appear to have installed that successfully, so you're halfway there.
There are a few different coverage plugins that work with pytest, and those need to be installed separately. Here are the two most common coverage plugins for Python and pytest:
https://pypi.org/project/coverage/
https://pypi.org/project/pytest-cov/
The first one, coverage is installed with:
pip install coverage
The second one, pytest-cov is installed with:
pip install pytest-cov
Based on your run command, you appear to want to use pytest-cov. After you've installed that, you can verify that pytest has those new options by calling pytest --help:
> pytest --help
...
coverage reporting with distributed testing support:
--cov=[SOURCE] Path or package name to measure during execution (multi-allowed). Use --cov= to
not do any source filtering and record everything.
--cov-reset Reset cov sources accumulated in options so far.
--cov-report=TYPE Type of report to generate: term, term-missing, annotate, html, xml (multi-
allowed). term, term-missing may be followed by ":skip-covered". annotate, html
and xml may be followed by ":DEST" where DEST specifies the output location.
Use --cov-report= to not generate any output.
--cov-config=PATH Config file for coverage. Default: .coveragerc
--no-cov-on-fail Do not report coverage if test run fails. Default: False
--no-cov Disable coverage report completely (useful for debuggers). Default: False
--cov-fail-under=MIN Fail if the total coverage is less than MIN.
...
Alternatively, you might be able to get the same results you're looking for using coverage:
coverage run -m pytest
coverage html
coverage report
And that will also give you a coverage report even if not using pytest-cov options.
I am trying to run a specific test method with pytest on Python 3.6 with the following command:
pytest sanity_test.py::test_check
(as mentioned in pytest docs)
and it fails with the following error message:
ERROR: not found: <rootdir>/tests/automation/sanity/sanity_test.py::test_check
(no name '<rootdir>/tests/automation/sanity/sanity_test.py::test_check' in any of [<DoctestModule 'tests/automation/sanity/sanity_test.py'>, <Module
'tests/automation/sanity/sanity_test.py'>])
when I run the whole test file the tests are running properly with:
pytest sanity_test.py
When I tried running a specific method in isolated project it works perfectly.
Any reason why pytest can't find specifically my test methods on my project?
The file is very simple and looks like this:
def test_check():
pass
Thank to hoefling, I recognized that I had --doctest-modules option in my setup.cfg file. Removing this option fixed the problem.
hoefling opened an issue in pytest for that problem.
I am new to pytest and I have python2.6 installed on my setup.
I installed pytest and the testcases get executed properly. I installed couple of plugins like pytest-timeout, putest-xdist etc but these plugins does not load when I run the cases. For timeout, I get following error: py.test: error: unrecognized arguments: --timeout
Same steps followed with python2.7 works.
Any idea how this can be solved or alteast steps to debug to know what exactly is causing the issue.
Unfortunately pytest < 3.0 "hides" the ImportError happening when failing to import a plugin. If you remove all plugin arguments but add -rw, you should be able to see what exactly is going wrong in the warning summary.
In your conftest.py file just add the following line after the imports:
pytest_plugins = 'pytest_timeout'
It should solve your issue.