Skip to content

Commit

Permalink
use module __getattr__ for py.error to fix doctesting
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Oct 19, 2022
1 parent 1b70fac commit 05b6c96
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/_pytest/_py/error.py
Expand Up @@ -5,7 +5,6 @@
import errno
import os
import sys
from types import ModuleType


class Error(EnvironmentError):
Expand Down Expand Up @@ -39,7 +38,7 @@ def __str__(self):
}


class ErrorMaker(ModuleType):
class ErrorMaker:
"""lazily provides Exception classes for each possible POSIX errno
(as defined per the 'errno' module). All such instances
subclass EnvironmentError.
Expand Down Expand Up @@ -97,5 +96,8 @@ def checked_call(self, func, *args, **kwargs):
__tracebackhide__ = True


error = ErrorMaker("_pytest._py.error")
sys.modules[error.__name__] = error
_error_maker = ErrorMaker()


def __getattr__(attr):
return getattr(_error_maker, attr)

0 comments on commit 05b6c96

Please sign in to comment.