VS Code unable to find pytest tests on M1 Mac - python

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?

Related

pylint gives error when run by tox, but not otherwise

I have been adding pylint and tox to a simple project: https://github.com/rrthomas/rpl/tree/tox
When I run pylint on my code, with some warnings turned off, I get no errors:
$ pylint --disable=C,fixme,too-many-locals,too-many-branches,too-many-statements rpl
-------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 9.68/10, +0.32)
However, when I run the same pylint command with tox, it gives me errors:
$ tox -e py310
...
py310 run-test: commands[2] | pylint --disable=C,fixme,too-many-locals,too-many-branches,too-many-statements rpl
************* Module rpl
rpl:356:11: E1101: Module 'regex' has no 'MULTILINE' member (no-member)
rpl:356:30: E1101: Module 'regex' has no 'IGNORECASE' member (no-member)
------------------------------------------------------------------
Your code has been rated at 9.68/10 (previous run: 9.68/10, +0.00)
I'm using the identical version of pylint both with and without tox.
I'm baffled, and I don't know whether I've done something wrong, or whether there's some problem, in which case, whose fault is it?
tox runs the tests in isolation. I'd guess tox is not moving the pylint configuration file so the pylint configuration is not automatically detected anymore by pylint. Try using the --rcfile option to specify the configuration file.
Add the --verbose flag to the pylint command which is run by tox. Then it tells you which configuration file is actually being used during the execution. The result is often rather unexpected.
I've written a bit more about the background here (albeit in a somewhat different context) .

Is Python 3.9.6 compatible with pytest 6.2.5?

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.

vscode python extension displayDiscoverStatus [SyntaxError: Unexpected end of JSON input

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)?

py.test: ImportError - cannot import ----

I am using someone else's code, available on GitHub. To run their code I created a virtualenv and installed all the dependencies listed - both python libraries and clones of other repositories. When I proceed to run the included tests, I get an ImportError:
Namespace(all=False, regr=False, sci=False, unit=True)
[localhost] local: py.test -x -v engine/test
==================================================================================== test session starts =====================================================================================
platform linux2 -- Python 2.7.6, pytest-2.8.2, py-1.4.31, pluggy-0.3.1 -- /home/compomics/local/METASPACE/SM_distributed/SM_engine/bin/python
cachedir: engine/test/.cache
rootdir: /home/compomics/local/METASPACE/SM_distributed/engine/test, inifile:
collecting 6 items / 1 errors
=========================================================================================== ERRORS ===========================================================================================
_______________________________________________________________________ ERROR collecting test_formula_img_validator.py _______________________________________________________________________
engine/test/test_formula_img_validator.py:7: in <module>
from engine.formula_img_validator import filter_sf_images,get_compute_img_measures, ImgMeasures
engine/formula_img_validator.py:7: in <module>
from pyIMS.image_measures import measure_of_chaos, isotope_image_correlation, isotope_pattern_match
E ImportError: cannot import name measure_of_chaos
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================================================================== 1 error in 0.99 seconds ===================================================================================
Fatal error: local() encountered an error (return code 2) while executing 'py.test -x -v engine/test'
However, if I open the python interpreter and try to do the exact same imports, it does it just fine without any error. Similar questions suggested:
adding an empty __init__.py to the test directory
making sure pytest is installed in the virtualenv
I did both these things, and the error persists.
I added to the beginning of the test script:
import os
print(os.environ["PYTHONPATH"].split(os.pathsep))
print(os.listdir("."))
and confirmed that the folder from where I'm trying to import is indeed in the resulting list.
Not sure how to proceed. Would appreciate any help I can get :)
In file formula_img_validator.py change
from pyIMS.image_measures import measure_of_chaos,isotope_image_correlation, isotope_pattern_match
to
from engine.pyIMS.image_measures import measure_of_chaos, isotope_image_correlation, isotope_pattern_match
That'll solve the problem. For complete solution go to GitHub for new updated code.
there was a conflict with other library
EDIT - this was my own stupidity for not remembering I had cloned a previous version of the dependent repos, which was also on my path, and that did not include the function this code was trying to load. Sorry for not having deleted the question when I noticed, I couldn't for the life of me find the delete button :)

VATIC Annotation Tool installation - "turkic setup --database" - unknown action setup

I'm trying to install VATIC Video Annotation Tool on Linux. I followed the instructions in README file twice, always failing to execute command:
$ turkic setup --database
which gives these two error messages:
No handlers could be found for logger "turkic.geolocation"
Error: Unknown action setup
Other turkic commands, e.g. turkic status --verify give the same error messages (for a given action name).
I also noticed that source file ~/vatic/public/index.html contains links to stylesheets and scripts in turkic folder src="/turkic/file_name", which can't be reached. Their true location is in ~/turkic/turkic/public.
Any ideas what can be wrong?
You should go into vatic folder when executing any commands starting with turkic.
Only inside vatic folder "actions" will be recognized.
Make sure that you issue the symbolic link command:
$ turkic setup --public-symlink

Categories