Skip to content

Commit

Permalink
Customize pytest collection to ignore feditest objects. (#274)
Browse files Browse the repository at this point in the history
Co-authored-by: Steve Bate <svc-atlassian@stevebate.net>
  • Loading branch information
steve-bate and Steve Bate authored Jul 27, 2024
1 parent 240d742 commit e6ff705
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
5 changes: 0 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,3 @@ exclude = [
max-line-length=120
disable="arguments-renamed, empty-docstring, global-variable-not-assigned, line-too-long, missing-class-docstring, missing-function-docstring, too-few-public-methods, too-many-arguments"


[tool.pytest.ini_options]
python_files = "test_*.py"
python_classes = "DoNotCollect" # Is there a better way of doing this?
python_functions = "test_*"
22 changes: 22 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# def pytest_pycollect_makeitem(collector, name, obj):
# module_name = getattr(obj, "__module__") if hasattr(obj, "__module__") else None
# if module_name and module_name.startswith("feditest."):
# print("@@@@@ Not collecting", obj, module_name)
# return None

import inspect

import pytest


@pytest.hookimpl(wrapper=True)
def pytest_pycollect_makeitem(collector, name, obj):
# Ignore all feditest classes and function using
# pytest naming conventions.
if isinstance(obj, type) or inspect.isfunction(obj) or inspect.ismethod(obj):
m = obj.__module__.split(".")
if len(m) > 0 and m[0] == "feditest":
yield
return None
result = yield
return result

0 comments on commit e6ff705

Please sign in to comment.