Overriding --errors-only=yes specified in rcfile - python

I use paver to run pylint as a task. In my rcfile(pylintrc) I have configured pylint to report only errors by setting errors-only=yes.
But I like to run paver pylint task with a verbose option to get it to report non-errors as well. How can I run pylint overriding the errors-only=yes setting?
Running with --errors-only=no gives an exception indicating that the --errors-only cannot be given a value. --enable=all also does not work.

This is an unexpected restriction that deserve an issue on the pylint's tracker (https://bitbucket.org/logilab/pylint/issues).
Though to get it works properly in your case, I would use a custom rc file for the task that wouldn't be used in my daily usage, eg pylint --rcfile=task.pylinrc ...

Related

Emacs - Python LSP setup.cfg not honored

I'm using vanilla Emacs and I installed lsp-mode as follows:
(use-package lsp-mode
:init
(setq lsp-keymap-prefix "C-c l")
:commands (lsp lsp-deferred)
:config (defun lsp-go-install-save-hooks ()
(add-hook 'before-save-hook #'lsp-format-buffer t t)
(add-hook 'before-save-hook #'lsp-organize-imports t t))
:hook (
(lsp-mode . lsp-enable-which-key-integration)
(go-mode . lsp-deferred)
(go-mode . lsp-go-install-save-hooks)
(typescript-mode . lsp-deferred)
(python-mode . lsp-deferred)
)
)
For Python I installed this. Everything seems to be working fine, but the problem is that I'm not able to override the default pycodestyle settings. For example, it complains about long lines > 79 so I tried adding in the root of the project the following setup.cfg:
[pycodestyle]
max-line-length=99
But it's not taken into account, am I missing something? I saw that there's the possibility to change the setting globally, but I'd like to have it on a per-project basis.
UPDATE
If pycodestyle is ran from the terminal it works as expected: it complains with the default line-length limit and it doesn't if I increase it to a value that is greater to the longest line that I have in the code.
The *lsp-log* buffer doesn't seem to provide any meaningful information:
Command "pyls" is not present on the path.
Command "pylsp" is present on the path.
Command "pyls" is not present on the path.
Command "pylsp" is present on the path.
Found the following clients for /<some path>/sample-app/sample_app/__init__.py: (server-id pylsp, priority -1)
The following clients were selected based on priority: (server-id pylsp, priority -1)
If I exec the flycheck-describe-checker command this is the output:
lsp is a Flycheck syntax checker.
This syntax checker checks syntax in the major mode(s)
`python-mode', `lsp-placeholder-mode', and uses a custom predicate.
Documentation:
A syntax checker using the Language Server Protocol (LSP)
provided by lsp-mode.
See https://github.com/emacs-lsp/lsp-mode.
If I disable flycheck by executing the command flycheck-disable-checker indeed the warnings go away, but it stops all the checks. So it seems like flycheck is the responsible for not honoring the setup.cfg.
I was able to understand what it seems to be happening. It seems that under the hood flycheck is using flake8 instead of pycodestyle. Indeed after I change setup.cfg into this:
[flake8]
max-line-length=99
Everything started working as expected.
The problem is that according to the documentation of python-lsp-server by default it should use pycodestyle. Moreover, checking through flake8 seems to be requiring 3rd party plugins according to the doc that I didn't install.
Not everything works as expected yet, as for example I have some complaints related to D100 and D104 that if I put them as ignore in the configuration their not honored yet.

Pytest coverage.py errror

I unit testing python code and running command pytest --cov, test is running fine but coverage is not getting displayed and error is
INTERNALERROR>raise CoverageException("Couldn't use data file {!r}:{}".format(self.filename, msg))
INTERNALERROR> coverage.misc.CoverageException: Couldn't use data file'C:\\Users\\Desktop\\Pytest\\.coverage': Safety level may not be changed inside a transaction
Need help with this problem?
This has been mentioned a few times in the coverage.py issues, and the eventual discovery was that it's a bug in Python 3.6.0, but if you use 3.6.1 or later, you will be fine.
If that doesn't cover your case, feel free to open an issue with details of how to reproduce.
Could be related to https://github.com/nedbat/coveragepy/issues/883#issuecomment-650562896 if you're using multiple pytests in parallel, in which case specifying a distinct coverage file for each run fixes it, like:
export COVERAGE_FILE=.coverage.SOMETHING_SPECIFIC_FOR_EACH_RUN
Use coverage==6.3.1
This works for me
Link to certain version https://pypi.org/project/coverage/6.3.1/

pytest - Windows fatal exception: code 0x8001010d

I am trying to run a GUI test using pytest and pywinauto. When I run the code normally, it does not complain.
However, when I am doing it via pytest, it throws a bunch of errors:
Windows fatal exception: code 0x8001010d
Note that the code still executes without problems and the cases are marked as passed. It is just that the output is polluted with these weird Windows exceptions.
What is the reason for this. Should I be concerned?
def test_01():
app = Application(backend='uia')
app.start(PATH_TO_MY_APP)
main = app.window(title_re="MY_APP")
main.wait('visible', timeout=8) # error occurs here
time.sleep(0.5)
win_title = f"MY_APP - New Project"
assert win_title.upper() == main.texts()[0].upper() # error occurs here
This is an effect of a change introduced with pytest 5.0.0. From the release notes:
#5440: The faulthandler standard library module is now enabled by default to help users diagnose crashes in C modules.
This functionality was provided by integrating the external pytest-faulthandler plugin into the core, so users should remove that plugin from their requirements if used.
For more information see the docs: https://docs.pytest.org/en/stable/usage.html#fault-handler
You can mute these errors as follows:
pytest -p no:faulthandler
I had the same problem with Python 3.7.7 32-bit and pytest 5.x.x. It was solved by downgrading pytest to v.4.0.0:
python -m pip install pytest==4.0
Perhaps all Python versions are not compatible with the newest pytest version(s).
My workaround for now is to install pytest==4.6.11
With 5.0.0 the problem occurs the first time.
W10 box.
Have this problem using pytest 6.2.5 and pytest-qt 4.0.2.
I tried np8's idea: still got a horrible crash (without message).
I tried Felix Zumstein's idea: still got a horrible crash (without message).
Per this thread it appears the issue (in 'Doze) is a crap DLL.
What's strange is that pytest-qt and the qtbot fixture seem to work very well... until I get to this one test. So I have concluded that I have done something too complicated in terms of mocking and patching for this crap 'Doze DLL to cope with.
For example, I mocked out two methods on a QMainWindow subclass which is created at the start of the test. But removing these mocks did not solve the problem.
I have so far spent about 2 hours trying to understand what specific feature of this test is so problematic. I am in fact trying to verify the functioning of a method on my main window class which "manufactures" menu items (QWidgets.QAction) based on about 4 parameters.
At this stage I basically have no idea what this "problem feature" is, but it might be the business of inspecting and examining the returned QAction object.

Why does py.test pass a unittest when Pyunit and nosetest fail it (as expected)?

I'm a complete new starter when it comes to writing python unittests and I know it's far far better and easier to write the tests before the code but I thought I'd start by contributing to a github project and fixing a few small issues and giving it a go.
One issue I was fixing was that if a argument wasn't given to an method, it would actually remove the argument on the server. I should mention that this project is a client for a REST API. This was easy enough to fix but I thought it would be good to write a test for it.
The code of the broken method is included within a class:
def edit_device(self, device, nickname=None, model=None, manufacturer=None):
data = {"nickname": nickname}
iden = device.device_iden
r = self._session.post("{}/{}".format(self.DEVICES_URL, iden), data=json.dumps(data))
I then was going to use Mock to mock the responses of the REST API using their documentation as the guide (it includes example responses).
The issue I am having is I have written my test as:
#mock.patch('pushbullet.pushbullet.requests.Session.get', side_effect=mocked_requests_get)
#mock.patch('pushbullet.pushbullet.requests.Session.post', side_effect=mocked_requests_post)
class TestPushbullet(object):
def test_edit_device_without_nickname(self, mock_get, mock_post):
pb = pushbullet.Pushbullet("API_KEY")
device = pb.devices[0]
new_device = pb.edit_device(device)
assert new_device.nickname == device.nickname
This seems to work correctly, the methods mocked_requests_get and mocked_requests_post get called. If I run this test within eclipse PyDev using pyUnit to run the pytest - it fails, as I expect. If I run the tests using nose it also fails, again perfect. If I run the test using py.test on the command line, it passes.
If I use the pytest.set_trace() as the first line in mocked_requests_post I can print args and it shows that the nickname is in fact not None and still set to what it is on the server (i.e. device.nickname so the assertion passes)
I can't for the life of me work out why py.test is not picking up the change in json from the self._session.post. If I change the iden in the URL format, it does indeed pick up that change, however changing the data body it does not.
Am I doing something intrinsically wrong? I can't see why py.test would pass and nose would fail on the same code.
EDIT: on the command line I'm running py.test path/to/single_test_file.py and the test file has only the single test method I've pasted above.
Finally worked it out, I must have installed the client package into python previous to deciding to write the tests. It looks like the command line py.test was therefore reading the client package from the true source (via pip install) whereas the IDE was reading it from the development package I had in eclipse.
Solution is to remove the package: pip uninstall <package>
Reinstall the development package: pip install -e . (when in the root development directory)

Pylint warning only shows up on Jenkins

When I run pylint locally, I don't see the warning. I really would not expect to see the warning at all. This occurs on at least 2 different versions of jenkins, currently running the latest version 1.576. The warning is shown in the UI using the Violations plug-in version 0.7.11 which is the latest.
This is the line of code that is tagged in the warning:
request.context.__parent__ = report # pylint: disable=W0201
And the warning it gives is 5 copies of W0201
This Warning was also disabled above in the code here:
#pylint: disable=R0901, R0904, R0914, W0201
Neither approach seems to have any effect.
Perhaps the pylintrc file is different between the machines/users.
Try copying your local ~/.pylintrc to your jenkins home folder.
Details for this are in here:
How do I disable a Pylint warning?

Categories

Resources