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

PytestConfigWarning for log_print, flake8-ignore, flake8-max-line-length #7612

Closed
marincandenza opened this issue Aug 3, 2020 · 6 comments · Fixed by #7614
Closed

PytestConfigWarning for log_print, flake8-ignore, flake8-max-line-length #7612

marincandenza opened this issue Aug 3, 2020 · 6 comments · Fixed by #7614
Labels
type: question general question, might be closed after 2 weeks of inactivity

Comments

@marincandenza
Copy link

marincandenza commented Aug 3, 2020

Executing our tests with PyTest 6.1 on Windows leads to PytestConfigWarning when parsing pytest.ini
Installed packages and pytest.ini is attached.

Thank you for providing powerful PyTest!

============================== warnings summary ===============================
venv\lib\site-packages\_pytest\config\__init__.py:1148
  C:\work\VV\vv-common\venv\lib\site-packages\_pytest\config\__init__.py:1148: PytestConfigWarning: Unknown config ini key: flake8-ignore
  
    self._warn_or_fail_if_strict("Unknown config ini key: {}\n".format(key))

venv\lib\site-packages\_pytest\config\__init__.py:1148
  C:\work\VV\vv-common\venv\lib\site-packages\_pytest\config\__init__.py:1148: PytestConfigWarning: Unknown config ini key: flake8-max-line-length
  
    self._warn_or_fail_if_strict("Unknown config ini key: {}\n".format(key))

venv\lib\site-packages\_pytest\config\__init__.py:1148
  C:\work\VV\vv-common\venv\lib\site-packages\_pytest\config\__init__.py:1148: PytestConfigWarning: Unknown config ini key: log_print
  
    self._warn_or_fail_if_strict("Unknown config ini key: {}\n".format(key))

-- Docs: https://docs.pytest.org/en/stable/warnings.html
======================== 1 passed, 3 warnings in 0.08s ========================

Process finished with exit code 0
(venv) C:\work>pip list
Package          Version
---------------- ---------
apipkg           1.5
atomicwrites     1.4.0
attrs            19.3.0
bcrypt           3.1.7
Cerberus         1.3.2
certifi          2020.6.20
cffi             1.14.1
chardet          3.0.4
colorama         0.4.3
crcmod           1.7
cryptography     3.0
execnet          1.7.1
idna             2.10
iniconfig        1.0.1
more-itertools   8.4.0
msgpack          1.0.0
numpy            1.19.1
packaging        20.4
paramiko         2.7.1
pip              19.2.3
pluggy           0.13.1
psutil           5.7.2
py               1.9.0
pycparser        2.20
PyNaCl           1.4.0
pyparsing        2.4.7
pyserial         3.4
pysftp           0.2.9
pytest           6.0.1
pytest-forked    1.3.0
pytest-html      2.1.1
pytest-metadata  1.10.0
pytest-variables 1.9.0
pytest-xdist     1.34.0
pythonping       1.0.10
PyVISA           1.10.1
PyVISA-py        0.4.1
PyYAML           5.3.1
requests         2.24.0
setuptools       41.2.0
setuptools-scm   4.1.2
six              1.15.0
testinfra        5.2.2
toml             0.10.1
urllib3          1.25.10
websocket-client 0.57.0
wheel            0.34.2
**pytest.ini**
[pytest]
norecursedirs = .eggs* build* .git* _build* tmp* dist* pytest_sick.egg-info* logs* venv*
yaml_loader = FullLoader
;addopts= --variables=config/04_emulator.yaml --junit-xml logs/junit.xml
addopts= --self-contained-html --tb=short
#--variables=config/04_emulator.yaml

markers =
    square: square tests (deselect with '-m "not slow"')
    others: other tests


;addopts = -n3                                  ; Run in three threads
;tb=short            ; [auto, long, short, line, native, no]: http://doc.pytest.org/en/latest/usage.html#modifying-python-traceback-printing

;Configures how durations are recorded into the JUnit XML report:
;total (the default): duration times reported include setup, call, and teardown times.
;call: duration times reported include only call times, excluding setup and teardown.
junit_duration_report = total

;Configures the format of the generated JUnit XML file. The possible options are:
;xunit1 (or legacy): produces old style output, compatible with the xunit 1.0 format. This is the default.
;xunit2: produces xunit 2.0 style output,
;which should be more compatible with latest Jenkins versions.
junit_family = xunit2

;Configures if stdout/stderr should be written to the JUnit XML file.
;Valid values are system-out, system-err, and no (the default).
junit_logging = system-out

;If junit_logging != "no", configures if the captured output should be written to the JUnit XML file for passing tests.
;Default is True.
junit_log_passing_tests = true

;To set the name of the root test suite xml item, you can configure the junit_suite_name option in your config file:
junit_suite_name = vv_common

;Sets the minimum log message level that should be captured for live logging.
;The integer value or the names of the levels can be used.
log_level = 9

;By setting the log_cli configuration option to true,
;pytest will output logging records as they are emitted directly into the console.
log_cli = true

;Sets the minimum log message level that should be captured for live logging.
;The integer value or the names of the levels can be used.
log_cli_level = 9

;Sets a time.strftime()-compatible string that will be used when formatting dates for live logging.
log_cli_date_format = %Y-%m-%d %H:%M:%S

;Sets a logging-compatible string used to format live logging messages.
log_cli_format = %(asctime)s.%(msecs)03d %(levelname)s %(name)s ==>> <<%(message)s>>

;Sets a logging-compatible string used to format logging messages redirected to the logging file.
log_file_format = %(asctime)s.%(msecs)03d %(levelname)s %(name)s ==>> <<%(message)s>>

;Sets the minimum log message level that should be captured for the logging file.
;The integer value or the names of the levels can be used.
log_file_level = 9

;Sets a file name relative to the pytest.ini file where log messages should be written to,
; in addition to the other logging facilities that are active.
;log_file=logs/pytest-logs.txt

;Sets a time.strftime()-compatible string that will be used when formatting dates for logging capture.
log_date_format = %Y-%m-%d %H:%M:%S

;Sets a time.strftime()-compatible string that will be used when formatting dates for the logging file.
log_file_date_format = %Y-%m-%d %H:%M:%S

;Sets a logging-compatible string used to format captured logging messages.
log_format = %(asctime)s.%(msecs)03d %(levelname)s %(name)s ==>> <<%(message)s>>

;If set to False, will disable displaying captured logging messages for failed tests.
log_print = True

; flake8 settings
flake8-max-line-length = 120
; Ignore settings for flake8
;E121=Continuation line under-indented for hanging indent -> sometimes its Black
;E501=Line too long -> excluded for generated code
;F405='object' may be undefined, or defined from star imports -> star import from generated code
;W291=trailing whitespace
;W293=blank line contains whitespace
;W391=Empty line at end of file
;W503=Line break before binary operator -> Black
flake8-ignore = crowns/*/*.py E501 F405 W291 W293
                cids/*/*.py E501 F405 W291 W293
                test_stubs/*/*.py E501 F405 W293
                W391
                E203    # black
                W503    # black
                doc/conf.py ALL
@The-Compiler
Copy link
Member

Why do you have flake8 configuration in a pytest.ini file? At least according to https://flake8.pycqa.org/en/latest/user/configuration.html that's not a place flake8 reads its config from.

@Zac-HD Zac-HD added the type: question general question, might be closed after 2 weeks of inactivity label Aug 3, 2020
@marincandenza
Copy link
Author

marincandenza commented Aug 3, 2020 via email

@The-Compiler
Copy link
Member

You don't have pytest-flake8 installed according to your pip list though, so those warnings make sense.

log_print was removed in pytest 6.0.0: 3f82006 - in other words, I think the only problem here is that it's still in the docs.

@marincandenza
Copy link
Author

marincandenza commented Aug 4, 2020

@The-Compiler
I removed log_print. Thank you for pointing this out.

You are right, flake8 is not locally installed.
Could you help me suppressing the warning messages?

I have tried in pytest.ini

filterwarnings =
    ignore:.*Unknown config ini key* flake8-ignore:PytestConfigWarning
    ignore:.*Unknown config ini key* flake8-max-line-length:PytestConfigWarning

but then, pytest does not recognize PytestConfigWarning:

File "venv\lib\site-packages_pytest\warnings.py", line 113, in catch_warnings_for_item
warnings.filterwarnings(*_parse_filter(arg, escape=False))
File "venv\lib\site-packages_pytest\warnings.py", line 39, in _parse_filter
category = warnings._getcategory(
File "Python\Python38\lib\warnings.py", line 266, in _getcategory
raise _OptionError("unknown warning category: %r" % (category,)) from None
warnings._OptionError: unknown warning category: 'PytestConfigWarning'

@The-Compiler
Copy link
Member

Try pytest.PytestConfigWarning instead (it needs to be the fully qualified name of a warning class Python has builtin or can import).

@marincandenza
Copy link
Author

@The-Compiler With pytest.PytestConfigWarning the INTERNALERROR is gone but I still get the warnings. I have event tried to ignore all PytestConfigWarning but with no success.

filterwarnings =
    ignore::pytest.PytestConfigWarning

This means, filterwarnings does nothing in my case. How can I suppress these warnings?

============================== warnings summary ===============================
venv\lib\site-packages_pytest\config_init_.py:1148
venv\lib\site-packages_pytest\config_init_.py:1148: PytestConfigWarning: Unknown config ini key: flake8-ignore

self._warn_or_fail_if_strict("Unknown config ini key: {}\n".format(key))

venv\lib\site-packages_pytest\config_init_.py:1148
venv\lib\site-packages_pytest\config_init_.py:1148: PytestConfigWarning: Unknown config ini key: flake8-max-line-length

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants