Skip to content
Open
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
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exclude = '''
\.git
| .tox
| build
| env
)/
'''

Expand All @@ -17,4 +18,5 @@ exclude = '''
[tool.isort]
profile = "black"
src_paths = ["src", "tests"]
skip_glob = "env/*"
known_first_party = "venusian"
23 changes: 12 additions & 11 deletions src/venusian/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,18 @@ def invoke(mod_name, name, ob):
return
for category in category_keys:
callbacks = attached_categories.get(category, [])
try:
# Metaclasses might trick us by reaching this far and then
# fail with too little values to unpack.
for callback, cb_mod_name, liftid, scope in callbacks:
if cb_mod_name != mod_name:
# avoid processing objects that were imported into
# this module but were not actually defined there
continue
callback(self, name, ob)
except ValueError: # pragma: nocover
continue
for cb_tuple in callbacks:
try:
# Metaclasses might trick us by reaching this far and then
# fail with too little values to unpack.
callback, cb_mod_name, liftid, scope = cb_tuple
except ValueError: # pragma: nocover
continue
if cb_mod_name != mod_name:
# avoid processing objects that were imported into
# this module but were not actually defined there
continue
callback(self, name, ob)

for name, ob in getmembers(package):
# whether it's a module or a package, we need to scan its
Expand Down
14 changes: 14 additions & 0 deletions tests/fixtures/callback_valueerror/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import venusian


def decorator(wrapped):
def callback(context, name, ob):
raise ValueError

venusian.attach(wrapped, callback)
return wrapped


@decorator
def function(request): # pragma: no cover
return request
9 changes: 9 additions & 0 deletions tests/test_venusian.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,15 @@ def ignore_child(name):
self.assertEqual(test.registrations[0]["ob"], func1)
self.assertEqual(test.registrations[0]["function"], True)

def test_valueerror_during_scan_in_callback(self):
from tests.fixtures import callback_valueerror

test = _Test()
scanner = self._makeOne(test=test)
# without a custom onerror, scan will propagate the importerror from
# will_cause_import_error
self.assertRaises(ValueError, scanner.scan, callback_valueerror)

def test_ignore_by_full_dotted_name(self):
from tests.fixtures import one

Expand Down