Skip to content

Commit

Permalink
test_wrapper_fail_obj_large() test disabled.
Browse files Browse the repository at this point in the history
This commit effectively disables the fragile hardware- and computational
load-sensitive `test_wrapper_fail_obj_large()` unit test, resolving test
issue #362 kindly submitted by fearless moé Debian packager
@WeepingClown13 (Ananthu C.V.). Specifically, this commit:

* Introduces a new kind of `pytest` skip condition named
  `skip_unless_godmode()`, documented as:

  ```rst
  Skip the decorated test or fixture unless the **current user** (i.e.,
  as identified by the POSIX-compatible ``${USER}`` shell variable) has
  **God-mode privileges** (i.e., is the principal maintainer of this
  package).

  An *extremely* small subset of tests and fixtures are sufficiently
  fragile as to warrant their isolation to God-mode-endowed users,
  typically due to making unsafe assumptions (e.g., hardware- and
  computational load-sensitive timing thresholds) that render those
  tests and fixtures unsuitable for a general audience. *There by
  God-mode dragons here.*
  ```

* Applies this skip condition to the `test_wrapper_fail_obj_large()`
  test.

This test now only runs for users with God-mode privileges. But... there
is only one such user. His username is @leycec! *Geh heh.* (*Mirthless dearth of unearthed dung!*)
  • Loading branch information
leycec committed Apr 10, 2024
1 parent f508586 commit 5bdbe24
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 55 deletions.
138 changes: 91 additions & 47 deletions beartype_test/_util/mark/pytskip.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,6 @@
# Sadly, the following imports require private modules and packages.
from _pytest.runner import Skipped

# ....................{ GLOBALS ~ constants }....................
_PYTHON_VERSION_TUPLE = sys.version_info[:3]
'''
Machine-readable version of the active Python interpreter as a tuple of
integers.
See Also
----------
:mod:`beartype.meta`
Similar logic performed at :mod:`beartype` importation time.
'''


_PYTHON_VERSION_STR = '.'.join(
str(version_part) for version_part in sys.version_info[:3])
'''
Human-readable version of the active Python interpreter as a dot-delimited
string.
See Also
----------
:mod:`beartype.meta`
Similar logic performed at :mod:`beartype` importation time.
'''

# ....................{ SKIP }....................
skip_if = pytest.mark.skipif
'''
Expand Down Expand Up @@ -93,14 +68,57 @@ def skip(reason: str):
Human-readable message justifying the skipping of this test.
Returns
----------
-------
pytest.skipif
Decorator skipping the decorated test with this justification.
'''
assert isinstance(reason, str), f'{repr(reason)} not string.'

return skip_if(True, reason=reason)


def skip_unless_godmode():
'''
Skip the decorated test or fixture unless the **current user** (i.e., as
identified by the POSIX-compatible ``${USER}`` shell variable) has
**God-mode privileges** (i.e., is the principal maintainer of this package).
An *extremely* small subset of tests and fixtures are sufficiently fragile
as to warrant their isolation to God-mode-endowed users, typically due to
making unsafe assumptions (e.g., hardware- and computational load-sensitive
timing thresholds) that render those tests and fixtures unsuitable for a
general audience. *There by God-mode dragons here.*
Returns
-------
pytest.skipif
Decorator describing these requirements if unmet *or* the identity
decorator reducing to a noop otherwise.
'''

# Defer heavyweight imports.
from beartype._util.os.utilosshell import get_shell_var_value_or_none

# Local name of the current user invoking the active Python interpreter if
# the current platform is POSIX-compatible *OR* "None" otherwise (e.g., if
# the current platform is vanilla Windows).
username = get_shell_var_value_or_none('USER')

# Skip this test if the current platform is POSIX-compatible *AND* the
# current user invoking the active Python interpreter is *NOT* a
# God-mode-endowed user (i.e., the principal maintainer of this package).
return skip_if(
username != 'leycec',
reason=(
(
f'User "{username}" lacks God-mode test privileges '
f"(i.e., is smart and knows what's good for them)."
)
if username else
'Current platform POSIX-noncompliant.'
),
)

# ....................{ SKIP ~ command }....................
def skip_unless_pathable(command_basename: str):
'''
Expand All @@ -114,7 +132,7 @@ def skip_unless_pathable(command_basename: str):
Basename of the command to be searched for.
Returns
----------
-------
pytest.skipif
Decorator describing these requirements if unmet *or* the identity
decorator reducing to a noop otherwise.
Expand All @@ -136,7 +154,7 @@ def skip_if_ci():
running under a remote continuous integration (CI) workflow.
Returns
----------
-------
pytest.skipif
Decorator skipping this text or fixture if this interpreter is
CI-hosted *or* the identity decorator reducing to a noop otherwise.
Expand All @@ -158,7 +176,7 @@ def skip_unless_os_linux():
running under either Microsoft Windows *or* Apple macOS.
Returns
----------
-------
pytest.skipif
Decorator skipping this text or fixture unless this interpreter is
running under a Linux distribution *or* the identity decorator reducing
Expand Down Expand Up @@ -188,7 +206,7 @@ def skip_unless_os_linux():
# superclass is a Python 3.7-compatible backport.
#
# Returns
# ----------
# -------
# pytest.skipif
# Decorator skipping this text or fixture if this interpreter is PyPy
# *or* the identity decorator reducing to a noop otherwise.
Expand Down Expand Up @@ -226,7 +244,7 @@ def skip_if_pypy():
optimization.
Returns
----------
-------
pytest.skipif
Decorator skipping this text or fixture if this interpreter is PyPy
*or* the identity decorator reducing to a noop otherwise.
Expand All @@ -252,13 +270,13 @@ def skip_if_python_version_greater_than_or_equal_to(version: str):
fixture as a dot-delimited string (e.g., ``3.5.0``).
Returns
----------
-------
pytest.skipif
Decorator describing these requirements if unmet *or* the identity
decorator reducing to a noop otherwise.
See Also
----------
--------
:mod:`beartype.meta`
Similar logic performed at :mod:`beartype` importation time.
'''
Expand Down Expand Up @@ -289,13 +307,13 @@ def skip_if_python_version_less_than(version: str):
fixture as a dot-delimited string (e.g., ``3.5.0``).
Returns
----------
-------
pytest.skipif
Decorator describing these requirements if unmet *or* the identity
decorator reducing to a noop otherwise.
See Also
----------
--------
:mod:`beartype.meta`
Similar logic performed at :mod:`beartype` importation time.
'''
Expand All @@ -320,19 +338,19 @@ def skip_unless_package(
'''
Skip the decorated test or fixture if the package with the passed name is
**unsatisfied** (i.e., either dynamically unimportable *or* importable but
of a version less than the passed minimum version if non-``None``).
of a version less than the passed minimum version if non-:data:`None`).
Parameters
----------
package_name : str
Fully-qualified name of the package to be skipped.
minimum_version : Optional[str]
Optional minimum version of this package as a dot-delimited string
(e.g., ``0.4.0``) to be tested for if any *or* ``None`` otherwise, in
which case any version is acceptable. Defaults to ``None``.
(e.g., ``0.4.0``) to be tested for if any *or* :data:`None` otherwise, in
which case any version is acceptable. Defaults to :data:`None`.
Returns
----------
-------
pytest.skipif
Decorator describing these requirements if unmet *or* the identity
decorator reducing to a noop otherwise.
Expand Down Expand Up @@ -362,10 +380,10 @@ def skip_unless_module(
'''
Skip the decorated test or fixture if the module with the passed name is
**unsatisfied** (i.e., either dynamically unimportable *or* importable but
of a version less than the passed minimum version if non-``None``).
of a version less than the passed minimum version if non-:data:`None`).
Caveats
----------
-------
**This decorator should never be passed the fully-qualified name of a
package.** Consider calling the :func:`skip_unless_package` decorator
instead to skip unsatisfied packages. Calling this decorator with package
Expand All @@ -378,11 +396,11 @@ def skip_unless_module(
Fully-qualified name of the module to be skipped.
minimum_version : Optional[str]
Optional minimum version of this module as a dot-delimited string
(e.g., ``0.4.0``) to be tested for if any *or* ``None`` otherwise, in
which case any version is acceptable. Defaults to ``None``.
(e.g., ``0.4.0``) to be tested for if any *or* :data:`None` otherwise, in
which case any version is acceptable. Defaults to :data:`None`.
Returns
----------
-------
pytest.skipif
Decorator describing these requirements if unmet *or* the identity
decorator reducing to a noop otherwise.
Expand Down Expand Up @@ -427,13 +445,14 @@ def _skip_if_callable_raises_exception(
Callable to be called.
args : Optional[Sequence]
Sequence of all positional arguments to unconditionally pass to the
passed callable if any *or* ``None`` otherwise. Defaults to ``None``.
passed callable if any *or* :data:`None` otherwise. Defaults to
:data:`None`.
kwargs : Optional[Mapping]
Mapping of all keyword arguments to unconditionally pass to the passed
callable if any *or* ``None`` otherwise. Defaults to ``None``.
callable if any *or* :data:`None` otherwise. Defaults to :data:`None`.
Returns
----------
-------
pytest.skipif
Decorator skipping this test if this callable raises this exception
*or* the identity decorator reducing to a noop otherwise.
Expand Down Expand Up @@ -466,3 +485,28 @@ def _skip_if_callable_raises_exception(

# Else, this callable raised no exception. Silently reduce to a noop.
return noop

# ....................{ PRIVATE ~ constants }....................
_PYTHON_VERSION_TUPLE = sys.version_info[:3]
'''
Machine-readable version of the active Python interpreter as a tuple of
integers.
See Also
--------
:mod:`beartype.meta`
Similar logic performed at :mod:`beartype` importation time.
'''


_PYTHON_VERSION_STR = '.'.join(
str(version_part) for version_part in sys.version_info[:3])
'''
Human-readable version of the active Python interpreter as a dot-delimited
string.
See Also
--------
:mod:`beartype.meta`
Similar logic performed at :mod:`beartype` importation time.
'''
21 changes: 13 additions & 8 deletions beartype_test/a00_unit/a70_decor/test_decorwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
# WARNING: To raise human-readable test errors, avoid importing from
# package-specific submodules at module scope.
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
from beartype_test._util.mark.pytskip import skip_if_ci

# ....................{ TESTS ~ fail : obj : large }....................
# Exclude this test from execution under remote continuous integration (CI)
# workflows. This test's implementation depends on a fixed-duration timeout and
# is thus overly fragile for remote environments not under our control, where
# test execution time is mostly a function of free data center resources.
@skip_if_ci()
from beartype_test._util.mark.pytskip import skip_unless_godmode

# ....................{ TESTS }....................
# Skip this test unless the current user has God-mode test privileges. This
# test's implementation requires a fixed-duration timeout, rendering this test
# hardware- and computational load-sensitive and thus overly fragile for both
# remote and local execution environments *NOT* under our direct control --
# especially remote continuous integration (CI) hosts, where test execution time
# is mostly a function of free data center resources.
@skip_unless_godmode()
def test_wrapper_fail_obj_large() -> None:
'''
Test unsuccessful usage of a wrapper function dynamically generated by the
Expand All @@ -38,13 +40,15 @@ def test_wrapper_fail_obj_large() -> None:
https://github.com/beartype/beartype/issues/91
'''

# ....................{ IMPORTS }....................
# Defer test-specific imports.
from beartype import beartype
from beartype.roar import BeartypeCallHintParamViolation
from beartype.typing import List
from pytest import raises
from time import time

# ....................{ LOCALS }....................
#FIXME: Ideally, this test would gracefully timeout (i.e., report failure
#after failing to pass for a certain reasonable duration of time).
#Pragmatically, pytest provides no official means of doing so and, while
Expand All @@ -70,6 +74,7 @@ def behold(the_great_destroyer_of_apps: List[List[List[int]]]) -> int:
# * Rapidly failing when that path has an unexpected speed regression.
BAD_APPLE = [[['a']*512]*256]*128

# ....................{ ASSERTS }....................
# Current time in fractional seconds since the UNIX epoch. Begin timing.
TIME_START = time()

Expand Down

0 comments on commit 5bdbe24

Please sign in to comment.