I test my SciPy installation using
python -c "import scipy; scipy.test('full', verbose=2)"
A single test (test_face) fails, while all other either passes or xfails. This one test fails because the dependency bz2 is lacking, which is fine. How can I specify that I want to skip this test entirely, while still running all other tests?
I'm using SciPy 1.2.0 with pytest 4.0.2.
I found a working solution using the extra_argv argument which passes the arguments on to pytest. From the pytest docs, -k "not test_face" may be used to skip exactly this test. In total then,
python -c "import scipy; scipy.test('full', verbose=2, extra_argv=['-k not test_face'])"
achieves what I wanted.
Related
Can you explain the prompt 'F6401' when I run pylint pylint-pytest plugin cannot enumerate and collect pytest fixtures. Please run `pytest --fixtures --collect-only path/to/current/module.py` and resolve any potential syntax error or package dependency issues (Can-enumerate-pytest-fixtures) is the reason?
I would like to know how it works, or why it appears, and sometimes has different outputs. The same code, sometimes two, sometimes more. I was depressed.
I did run pytest --fixtures --collect-only without any unusual hints and my tests were normal.
Description:
After I fine-tune my existing code, including running pylint, pytest, and isort, everything works. I added a new package executor with three modules, one is the abstract module of base.py, two are corresponding to different implementation modules(local.py, docker.py).
Then I run isort, and pylint works fine
Then I import the base class and two implementation classes in the module's __init__.py file, and add a factory method.
When I run pylint again, the input tells me that some of the test modules have problems with F6401.
Again, I want to emphasize that everything was fine until I added this module. But now I just added the source code of this module, this exception will appear.
What makes it even more confusing to me is that the module I'm prompted doesn't include any fixtures. I ran pylint again and found that F6401 has more test modules (several times more than last time).
I've been using PyLint for a new project to check for a mode-by-module migration, and when I migrate to this module, I can't continue.
OS env
python 3.7
os: Deepin(base Debian)
IDE: Pycharm
Package versions
pylint 3.0.0a3
pylint-pytest 1.1.2
pyparsing 2.4.7
pytest 6.2.3
pytest-asyncio 0.14.0
pytest-cov 2.11.1
pytest-mock 3.5.1
ISSUE about this question.
After debugging the source code, I found out that the cause of my problems was an error in pylint-pytest when running pytest to collect fixtures from source code, and then pylint-pytest passed the error to PyLint.
My source code had a type annotation error that caused pytest to look for a fixture from that module that was wrong, and the error was passed to pylint. But why there is a different output is not clear to me.
From debugging the source code, we know that pylint-pytest registers itself with pylint, and when pylint checks all files, it passes the files to pylint-pytest's FixtureChecker.
https://github.com/reverbc/pylint-pytest/blob/62676386f80989cc0373d77bc5dc74acc635fd7a/pylint_pytest/checkers/fixture.py#L92-L142
The visit_module method in the FixtureChecker passes the file to pytest, running pytest <module_file> --fixtures --collect-only, At the same time load the FixtureCollector plug-in into pytest.
https://github.com/reverbc/pylint-pytest/blob/62676386f80989cc0373d77bc5dc74acc635fd7a/pylint_pytest/checkers/fixture.py#L125-L131
In pytest_collectreport , if an error is reported by pytest, it is logged and the error information is passed to pytest.
https://github.com/reverbc/pylint-pytest/blob/62676386f80989cc0373d77bc5dc74acc635fd7a/pylint_pytest/checkers/fixture.py#L24-L34
I don't think this logic makes sense. Pytest should only collect fixtures from the test modules, and instead of collecting fixtures from all modules, Pylint-Pytest should filter out the source code when PyLint checks.
At this point, my doubts have disappeared. Thanks.
The documentation for pytest suggests you can skip certain imports:
https://docs.pytest.org/en/latest/skipping.html#skipping-on-a-missing-import-dependency
We are trying to run pylint under pytest and in some cases importing tensorflow causes issues because of system dependencies. The documentation shows a way of skipping the import in code, is it possible to skip imports like this from the command line of pytest?
There is no such feature in pytest, so you should do this directly in code (usually in a conftest.py).
A hacky workaround to do the same directly at the command line woud be:
python -c "import pytest; pytest.importorskip('tensorflow'); pytest.main()"
Better would be to use one of the existing hooks to add your own command-line option to pytest, so it can be specified clearly like --no-tensorflow or whatever.
When I am trying to use F2PY, I'll get the error:
Failed to import Numeric: No module named Numeric
I know that numeric is dead and instead we should use numpy. But files:
/usr/local/lib/python2.7/dist-packages/f2py2e/src/fortranobject.h and
/usr/local/lib/python2.7/dist-packages/f2py2e/f2py2e.py both use the Numeric package. I tried to replace it with numpy, but I was not successful.
I used to use f2py without any problem, but after I formatted my computer and got a fresh copy of Ubuntu, I have this problem.
I also tried to use the option --2d-numpy for f2py like:
f2py -c --fcompiler=intel --2d-numpy -m processoutput processoutput.f
But it didn't work, and it is still looking for numpy.
Thank you for your help.
I ran into a similar situation using msys under Windows, and indeed I was trying to use an outdated version of f2py. The newer version is included with numpy (and doesn't need to be installed separately). And can be found in the site-packages/numpy/f2py directory. Although my setup is a bit different, I was able to compile from python using this script:
import numpy.f2py.f2py2e as f2py2e
import sys
sys.argv += "-c -m hello hello.f".split()
f2py2e.main()
You can download old versions of Numeric here: http://sourceforge.net/projects/numpy/files/Old%20Numeric/24.2/
If you install that, I think f2py will be satisfied.
I'm using Sublime Text 3 With Pylinter to run pylint on my files.
However, on the same machine, I work on files for both python 2, and python 3 projects (the code is executed on one of several remote test-VMs, via SSH. I'm modifying the files by opening them over SMB. This is my home test-lab, and I'm finally sitting down to learn py3k).
Can I easily override the mechanism pylint uses to determine the python version it should lint for? Ideally, there would be an inline directive, but I have not had much luck finding anything.
I'm (editing) on Windows (the remote VMs are linux, but that' irrelevant here), for what it's worth.
You can try python2 -m pylint ... and python3 -m pylint .... That ensures that you use the right version.
AFAIK Pylint lints for the version of Python it is running on and it is not possible to override it.
Expanding on #sthenault's answer and borrowing heavily from #simon's to a very similar question on askubuntu, the solution is to write a wrapper script around pylint that executes it with the appropriate version of the Python interpreter. Drop the following into a script called mypylint (or whatever) somewhere in your $PATH:
#! /usr/bin/env bash
python_interpreter="python${1}"
pylint_args="-f colorized ${#:2}"
pylint_import=$(cat << PYTHON
import sys
import pkg_resources
__requires__ = "pylint"
sys.exit(
pkg_resources.load_entry_point("pylint", "console_scripts", "pylint")()
)
PYTHON
)
$python_interpreter -c "$pylint_import" $pylint_args
Then, execute it like so: mypylint 2|3 PYLINT_ARGS. For instance:
mypylint 2 -f colorized module.py
I'm not sure how you can tie that into sublime-text, but it more generally answers the question of parallel versions of pylint. I also bundled the above solution into a gist.
This is good, but I think the simplest thing is just to use virtualenv, and install pylint in each virtualenv. The correct pylint and python interpreter will be used.
You can override on a per-project level in Sublime Text by changing the pylint executable setting in Project->Edit Project to include:
"settings":
{
"SublimeLinter.linters.pylint.executable": ["py", "-3.4", "-m", "pylint"],
}
substituting 3.4 for your preferred flavour
You should have two pylint installations, say pylint2 and pylint3, then write a wrapper script that will subprocess the desired one.
You can install pylint3 which will evaluate for python 3.0, and pylint which will evaluate the code as python 2.7 by default.
I'm use pytest with some parameterized tests. However, in more recent versions of pytest with keywords matching becoming more complex I can't figure out how to match a specific paramterization of the test.
If I run my tests they look like
test_abc[backend_generator0-1]
test_abc[backend_generator0-2]
etc. But I can't figure out how to run a specific test parameterization.
pytest -k "test_abc[backend_generator0-2]"
gives Syntax Error
test_simple_delay[backend_generator1not 2]
I've tried various attempts at escaping the - to match only the specific test but without success.
This python 2.7 on pytest 2.3.5
You don't need -k or escapes for this. Use the node ID directly:
py.test 'test_abc[backend_generator0-1]'
You can just do py.test -k "test_abc and generator0" i guess.