Skip to content

Commit

Permalink
add hack to make unittest print full test paths; also remove nose as …
Browse files Browse the repository at this point in the history
…a dep
  • Loading branch information
giampaolo committed Oct 5, 2016
1 parent acfe6b2 commit a084e7f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
12 changes: 3 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ DEPS = argparse \
ipaddress \
ipdb \
mock==1.0.1 \
nose \
pep8 \
pyflakes \
requests \
Expand Down Expand Up @@ -130,15 +129,10 @@ test-memleaks: install
test-platform: install
$(PYTHON) psutil/tests/test_`$(PYTHON) -c 'import psutil; print([x.lower() for x in ("LINUX", "BSD", "OSX", "SUNOS", "WINDOWS") if getattr(psutil, x)][0])'`.py

# Run a specific test by name; e.g. "make test-by-name disk_" will run
# all test methods containing "disk_" in their name.
# Requires "pip install nose".
# Run a specific test by name, e.g.
# make test-by-name psutil.tests.test_system.TestSystemAPIs.test_cpu_times
test-by-name: install
@$(PYTHON) -m nose psutil/tests/*.py --nocapture -v -m $(filter-out $@,$(MAKECMDGOALS))

# Same as above but for test_memory_leaks.py script.
test-memleaks-by-name: install
@$(PYTHON) -m nose test/test_memory_leaks.py --nocapture -v -m $(filter-out $@,$(MAKECMDGOALS))
@$(PYTHON) -m unittest -v $(filter-out $@,$(MAKECMDGOALS))

coverage: install
# Note: coverage options are controlled by .coveragerc file
Expand Down
13 changes: 13 additions & 0 deletions psutil/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,19 @@ def create_temp_file(suffix=None):
# ===================================================================


class TestCase(unittest.TestCase):

def __str__(self):
return "%s.%s.%s" % (
self.__class__.__module__, self.__class__.__name__,
self._testMethodName)


# Hack that overrides default unittest.TestCase in order to print
# a full path representation of the single unit tests being run.
unittest.TestCase = TestCase


def retry_before_failing(retries=NO_RETRIES):
"""Decorator which runs a test function and retries N times before
actually failing.
Expand Down
2 changes: 2 additions & 0 deletions psutil/tests/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
x.startswith('test_memory_leaks')]
suite = unittest.TestSuite()
for tm in testmodules:
# ...so that "make test" will print the full test paths
tm = "psutil.tests.%s" % tm
suite.addTest(unittest.defaultTestLoader.loadTestsFromName(tm))
result = unittest.TextTestRunner(verbosity=VERBOSITY).run(suite)
success = result.wasSuccessful()
Expand Down

0 comments on commit a084e7f

Please sign in to comment.