Skip to content

Commit

Permalink
skip_fixtures: event_loop and httpx_mock. new build infra
Browse files Browse the repository at this point in the history
  • Loading branch information
cybergrind committed Feb 4, 2024
1 parent 5bad7c1 commit 58c5fa4
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 84 deletions.
28 changes: 28 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
max_line_length = 100

[**.py]
indent_style = space
indent_size = 4
emacs_py_project = .
emacs_py_formatter = ruff
# emacs_py_save_touch = infra/uwsgi.ini
# other variables:
# emacs_py_test_command
# emacs_py_test_full_path
# emacs_py_project_root
# emacs_py_extra_path
# emacs_py_interactive

[frontend/**.{js,jsx}]
indent_style = space
indent_size = 2
# emacs_py_save_touch = frontend/package.json


[Makefile]
indent_style = tab
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ wheelhouse/
.tox
.coverage.*
*,cover
/.envrc
1 change: 1 addition & 0 deletions .projectile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-/venv
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

13 changes: 13 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
extends: default

rules:
line-length:
max: 100
level: warning

truthy:
allowed-values: ['true', 'false', 'yes', 'no']

indentation:
indent-sequences: whatever
84 changes: 84 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
[project]
name = 'pytest-tipsi-testing'
dynamic = ["version"]
description = 'Better fixtures management. Various helpers'
readme = "README.rst"
authors = [
{ name = 'cybergrind', email = '[email protected]' }
]
keywords = ['testing', 'asyncio']
dependencies = [
'pytest>=3.3.0',
]
classifiers = [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: Implementation',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Software Development',
'Topic :: Software Development :: Libraries',
'Topic :: Utilities',
]

[project.urls]
github = 'https://github.com/tipsi/pytest-tipsi-testing'

[project.optional-dependencies]
log_requests = ['requests~=2.18.0']
test = ['coverage', 'pytests']

[tool.hatch.version]
path = "pytest_tipsi_testing/__init__.py"

[build-system]
requires = ['setuptools', 'wheel', 'hatchling']
build-backend = 'hatchling.build'

[tool.hatch.build]
exclude = [
'.*',
'.gitignore',
'tox.ini',
'tests'
]

[tool.hatch.commands]
prerelease = 'hatch build'


[tool.ruff]
line-length = 100
select = [
"E", # pycodestyle
"F", # pyflakes
"I", # isort
"G", # flake8-logging-format
"ASYNC", # flake8-async
"PIE", # flake8-pie
"T20", # flake8-print
"PT", # flake8-pytest-style
"Q", # flake8-quotes
]
ignore = [
"Q001",
"Q003"
]

[tool.ruff.format]
quote-style = "single"

[tool.ruff.lint.isort]
combine-as-imports = true
known-first-party = ['snapshot_manager']
lines-after-imports = 2

[tool.ruff.lint.flake8-quotes]
docstring-quotes = "double"
inline-quotes = "single"
multiline-quotes = "single"
2 changes: 1 addition & 1 deletion pytest_tipsi_testing/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.3.4'
__version__ = '1.4.0'
27 changes: 20 additions & 7 deletions pytest_tipsi_testing/plugin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import os
import traceback
from contextlib import suppress, contextmanager
from contextlib import contextmanager, suppress
from pprint import pformat
from unittest.mock import patch
from urllib.parse import urlparse
Expand All @@ -13,6 +13,7 @@ def gen_vprint(curr_level):
def _inner(*args, level=1, **kwargs):
if level <= curr_level:
print(*args, **kwargs)

return _inner


Expand All @@ -22,7 +23,7 @@ def vprint_func(*args, level=1, **kwargs):

@pytest.fixture(scope='session')
def vprint():
yield vprint_func
return vprint_func


@pytest.hookimpl(trylast=True)
Expand All @@ -46,7 +47,16 @@ def pytest_fixture_setup(fixturedef, request):
return

vprint_func('FDEF: {} {}'.format(fixturedef, request), level=4)
skip_fixtures = set([request.fixturename, 'module_transaction', 'request', 'auto_transaction'])
skip_fixtures = set(
[
request.fixturename,
'module_transaction',
'request',
'auto_transaction',
'event_loop',
'httpx_mock',
]
)

for scope in ['session', 'package', 'module', 'class', 'function']:
_lvl = scope
Expand All @@ -62,8 +72,9 @@ def pytest_fixture_setup(fixturedef, request):
_lvl = None
return

assert name in request._arg2fixturedefs, \
'There is no fixture `{}` in scope => {}'.format(name, request.node.nodeid)
assert (
name in request._arg2fixturedefs
), 'There is no fixture `{}` in scope => {}'.format(name, request.node.nodeid)
fdef = request._arg2fixturedefs[name][0]

if fdef.scope == scope:
Expand Down Expand Up @@ -115,14 +126,15 @@ def tipsi_pformat(something):
return pformat(something, indent=2)


@pytest.fixture
@pytest.fixture()
def log_requests(request):
"""
read more in README.rst
we don't force to install requests into project as a dependency
if you're not using log_requests
"""
import requests # see docstring

original_request = requests.sessions.Session.request
records = []

Expand Down Expand Up @@ -155,4 +167,5 @@ def _ret(doc_path, items=slice(None)):
with open(fname, 'w') as f:
json.dump(records[items], f)
records = []
yield _ret

return _ret
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

60 changes: 0 additions & 60 deletions setup.py

This file was deleted.

0 comments on commit 58c5fa4

Please sign in to comment.