Skip to content

Commit

Permalink
Merge pull request #1 from birnevogel11/02-verbose-skip
Browse files Browse the repository at this point in the history
feat: show skipped attributed tests
  • Loading branch information
aigarius authored Jan 3, 2024
2 parents f5e093c + e9ebaa3 commit d837112
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 64 deletions.
22 changes: 0 additions & 22 deletions .github/workflows/py33.yml

This file was deleted.

7 changes: 3 additions & 4 deletions .github/workflows/tox-gh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ on:

jobs:
build:
# ubuntu-22 doesnt support Python 2.7
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9, '3.10']
python-version: [3.8, 3.9, '3.10']
name: main
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
Expand Down
28 changes: 23 additions & 5 deletions nose/plugins/attrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ def test_end_to_end_something(self):
from nose.plugins.base import Plugin
from nose.util import tolist

log = logging.getLogger('nose.plugins.attrib')
compat_24 = sys.version_info >= (2, 4)

def attr(*args, **kwargs):
Expand All @@ -124,7 +123,7 @@ def wrap_ob(ob):
return wrap_ob

def get_method_attr(method, cls, attr_name, default = False):
"""Look up an attribute on a method/ function.
"""Look up an attribute on a method/ function.
If the attribute isn't found there, looking it up in the
method's class, if any.
"""
Expand All @@ -139,7 +138,7 @@ def get_method_attr(method, cls, attr_name, default = False):

class ContextHelper:
"""Object that can act as context dictionary for eval and looks up
names as attributes on a method/ function and its class.
names as attributes on a method/ function and its class.
"""
def __init__(self, method, cls):
self.method = method
Expand All @@ -156,6 +155,7 @@ class AttributeSelector(Plugin):
def __init__(self):
Plugin.__init__(self)
self.attribs = []
self.verbose_skipped = False

def options(self, parser, env):
"""Register command line options"""
Expand All @@ -165,6 +165,12 @@ def options(self, parser, env):
metavar="ATTR",
help="Run only tests that have attributes "
"specified by ATTR [NOSE_ATTR]")
parser.add_option("--verbose-skipped-attr",
dest="verbose_skipped_attr",
default=False,
action="store_true",
help="Show debug messages when the test case is skipped")

# disable in < 2.4: eval can't take needed args
if compat_24:
parser.add_option("-A", "--eval-attr",
Expand All @@ -184,6 +190,7 @@ def configure(self, options, config):
match.
"""
self.attribs = []
self.logger = logging.getLogger('nose.plugins.attrib')

# handle python eval-expression parameter
if compat_24 and options.eval_attr:
Expand Down Expand Up @@ -227,6 +234,11 @@ def eval_in_context(expr, obj, cls):
if self.attribs:
self.enabled = True

self.verbose_skipped = options.verbose_skipped_attr
if self.verbose_skipped:
self.logger.setLevel(logging.DEBUG)
self.logger.debug("Show skipped attr tests later ...")

def validateAttrib(self, method, cls = None):
"""Verify whether a method has the required attributes
The method is considered a match if it matches all attributes
Expand Down Expand Up @@ -274,7 +286,10 @@ def validateAttrib(self, method, cls = None):
def wantFunction(self, function):
"""Accept the function if its attributes match.
"""
return self.validateAttrib(function)
is_valid = self.validateAttrib(function)
if self.verbose_skipped and not is_valid:
self.logger.debug("Skip the test: %s", function.__name__)
return is_valid

def wantMethod(self, method):
"""Accept the method if its attributes match.
Expand All @@ -286,4 +301,7 @@ def wantMethod(self, method):
cls = method.__self__.__class__
except AttributeError:
return False
return self.validateAttrib(method, cls)
is_valid = self.validateAttrib(method, cls)
if self.verbose_skipped and not is_valid:
self.logger.debug("Skip the test method: %s", method.__name__)
return is_valid
Loading

0 comments on commit d837112

Please sign in to comment.