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

Customize pytest collection to ignore feditest objects. #274

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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