Skip to content

Commit

Permalink
test: add pyproject.toml: set pytest and ruff project defaults
Browse files Browse the repository at this point in the history
Pytest 6 is required to use this. This means it works only for python3.

It includes a dummy setting for redis password assuming redis is
running at the default port. This requires pytest-env be installed.

At some point I expect to add project and build-system tables to allow
building using the build package. The version and long_description
specifiers in the project table will be dynamic since the version is
from roundup/__init__.py and description from doc/announcement.txt.

One open issue is how to support the equivalent of:

  python setup.py build_doc

to run sphinx over the docs and include them in the share directory
bundled with the distributions.

Modified test_redis_session.py to better handle empty password.
  • Loading branch information
rouilj committed Mar 23, 2024
1 parent be0d99e commit 22653b5
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 1 deletion.
111 changes: 111 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
[tool.pytest.ini_options]
# Note this only works under python3. Pytest 6.0+ supports
# pyproject.toml and is not available for python 2. These settings can
# be adapted for pytest.ini if you are running under python2.

# For use with packages:
# python -m pip install pytest-cov pytest-env pytest-randomly

minversion = "6.0"

# Disable randomly by default. There are still a few tests that are
# order dependent. Enable on cli for python3 only using:
# "-p randomly"
addopts = "-p no:randomly --durations=10 --strict-markers -r a -v"

# Set the redis password to nothing. Can be overridden on cli using:
# "-e pytest_redis_pw=mySecretPassword"
env = [
"D:pytest_redis_pw="
]

# Don't search random directories to find tests.
testpaths = [
"test",
]

[tool.ruff]
line-length = 128
output-format = "full"

exclude = [
# ignore code imported/sourced from other places
"roundup/cgi/PageTemplates/*.py",
"roundup/cgi/TAL/*.py",
"roundup/cgi/ZTUtils/*.py",
"roundup/anypy/vendored/*.py",
"dicttoxml.py"
]

[tool.ruff.lint]
select = [
"A", # flake-8-builtins shadowing a builtin
"ARG", # flake8-unused-arguments
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"C901", # McCabe complexity
"COM", # flake8-commas
"E",
"F", # pyflakes
"G", # logging format _(.... % ...) bad use _(...) % ...
"I", # imports
"INT", # check gettext
"Q", # quoting consistancy
"PERF", # performance lint
"PIE794", # duplicate class field definition
"PL", # pylint
"RET", # check for inconistent returns
"RUF", # ruff
"S", # bandit - security
"SIM", # simplify code
"T10", # flake8-debugger
"W", # pycode whitespace warnings
]

ignore = [
# raise from except hander with none or chaining; only python3
"B904",
# ### before comments is fine
"E266",
# ignore double vs. single quotes
"Q000", "Q001", "Q002",
# do not replace x in (a,b) with x in {a,b} (set). python 3.2
# got a speedup in this; only python 3
"PLR6201",
# 505: allow use of else/elif even if it could be removed.
# if X: return; elif Z: return; else v ->
# if X: return; if Z: return; v
# 506: same but with a raise rather than return
#"RET505",
#"RET506",
# use *list to expand; only python 3
"RUF005",
# do not use contextlib.suppress rather than except: pass to suppress
# exception. contextlib doesn't work in python2 and is slower
"SIM105",
]


[tool.ruff.lint.per-file-ignores]
"roundup/anypy/*.py" = ["RET505", "RET506"]
"roundup/dehtml.py" = ["E501"]
"roundup/rest.py" = ["E501"]
"roundup/support.py" = ["E401"]
"roundup/security.py" = ["E701"]
"roundup/date.py" = ["E231", "E701"]
"roundup/backends/back_sqlite.py" = [ "E203" ]

[too.ruff.lint.pylint]
max-args = 6
max-branches=20
max-statements = 100

[tool.ruff.lint.mccabe]
max-complexity = 50

#
#skip=
# C901
# E228
# E302
# E401
2 changes: 1 addition & 1 deletion test/test_redis_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def setUp(self):
SessionTest.setUp(self)

import os
if 'pytest_redis_pw' in os.environ:
if 'pytest_redis_pw' in os.environ and os.environ['pytest_redis_pw']:
pw = os.environ['pytest_redis_pw']
if ':' in pw:
# pw is user:password
Expand Down

0 comments on commit 22653b5

Please sign in to comment.