Skip to content

Commit

Permalink
try to set PSUTIL_TESTING env var from python before failing
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Nov 11, 2017
1 parent 02e25d7 commit ffde326
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
35 changes: 18 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ DEPS = \

# In not in a virtualenv, add --user options for install commands.
INSTALL_OPTS = `$(PYTHON) -c "import sys; print('' if hasattr(sys, 'real_prefix') else '--user')"`
TEST_PREFIX = PYTHONWARNINGS=all PSUTIL_TESTING=1

all: test

Expand Down Expand Up @@ -108,53 +109,53 @@ setup-dev-env: ## Install GIT hooks, pip, test deps (also upgrades them).

test: ## Run all tests.
${MAKE} install
PSUTIL_TESTING=1 PYTHONWARNINGS=all $(PYTHON) $(TSCRIPT)
$(TEST_PREFIX) $(PYTHON) $(TSCRIPT)

test-process: ## Run process-related API tests.
${MAKE} install
PSUTIL_TESTING=1 PYTHONWARNINGS=all $(PYTHON) -m unittest -v psutil.tests.test_process
$(TEST_PREFIX) $(PYTHON) -m unittest -v psutil.tests.test_process

test-system: ## Run system-related API tests.
${MAKE} install
PSUTIL_TESTING=1 PYTHONWARNINGS=all $(PYTHON) -m unittest -v psutil.tests.test_system
$(TEST_PREFIX) $(PYTHON) -m unittest -v psutil.tests.test_system

test-misc: ## Run miscellaneous tests.
${MAKE} install
PSUTIL_TESTING=1 PYTHONWARNINGS=all $(PYTHON) psutil/tests/test_misc.py
$(TEST_PREFIX) $(PYTHON) psutil/tests/test_misc.py

test-unicode: ## Test APIs dealing with strings.
${MAKE} install
PSUTIL_TESTING=1 PYTHONWARNINGS=all $(PYTHON) psutil/tests/test_unicode.py
$(TEST_PREFIX) $(PYTHON) psutil/tests/test_unicode.py

test-contracts: ## APIs sanity tests.
${MAKE} install
PSUTIL_TESTING=1 PYTHONWARNINGS=all $(PYTHON) psutil/tests/test_contracts.py
$(TEST_PREFIX) $(PYTHON) psutil/tests/test_contracts.py

test-connections: ## Test net_connections() and Process.connections().
${MAKE} install
PSUTIL_TESTING=1 PYTHONWARNINGS=all $(PYTHON) psutil/tests/test_connections.py
$(TEST_PREFIX) $(PYTHON) psutil/tests/test_connections.py

test-posix: ## POSIX specific tests.
${MAKE} install
PSUTIL_TESTING=1 PYTHONWARNINGS=all $(PYTHON) psutil/tests/test_posix.py
$(TEST_PREFIX) $(PYTHON) psutil/tests/test_posix.py

test-platform: ## Run specific platform tests only.
${MAKE} install
PSUTIL_TESTING=1 PYTHONWARNINGS=all $(PYTHON) psutil/tests/test_`$(PYTHON) -c 'import psutil; print([x.lower() for x in ("LINUX", "BSD", "OSX", "SUNOS", "WINDOWS", "AIX") if getattr(psutil, x)][0])'`.py
$(TEST_PREFIX) $(PYTHON) psutil/tests/test_`$(PYTHON) -c 'import psutil; print([x.lower() for x in ("LINUX", "BSD", "OSX", "SUNOS", "WINDOWS", "AIX") if getattr(psutil, x)][0])'`.py

test-memleaks: ## Memory leak tests.
${MAKE} install
PSUTIL_TESTING=1 PYTHONWARNINGS=all $(PYTHON) psutil/tests/test_memory_leaks.py
$(TEST_PREFIX) $(PYTHON) psutil/tests/test_memory_leaks.py

test-by-name: ## e.g. make test-by-name ARGS=psutil.tests.test_system.TestSystemAPIs
${MAKE} install
@PSUTIL_TESTING=1 PYTHONWARNINGS=all $(PYTHON) -m unittest -v $(ARGS)
@$(TEST_PREFIX) $(PYTHON) -m unittest -v $(ARGS)

test-coverage: ## Run test coverage.
${MAKE} install
# Note: coverage options are controlled by .coveragerc file
rm -rf .coverage htmlcov
PSUTIL_TESTING=1 PYTHONWARNINGS=all $(PYTHON) -m coverage run $(TSCRIPT)
$(TEST_PREFIX) $(PYTHON) -m coverage run $(TSCRIPT)
$(PYTHON) -m coverage report
@echo "writing results to htmlcov/index.html"
$(PYTHON) -m coverage html
Expand Down Expand Up @@ -199,7 +200,7 @@ upload-src: ## Upload source tarball on https://pypi.python.org/pypi/psutil.
$(PYTHON) setup.py sdist upload

win-download-exes: ## Download exes/wheels hosted on appveyor.
PYTHONWARNINGS=all $(PYTHON) scripts/internal/download_exes.py --user giampaolo --project psutil
$(TEST_PREFIX) $(PYTHON) scripts/internal/download_exes.py --user giampaolo --project psutil

win-upload-exes: ## Upload wheels in dist/* directory on PYPI.
$(PYTHON) -m twine upload dist/*.whl
Expand All @@ -225,10 +226,10 @@ release: ## Create a release (down/uploads tar.gz, wheels, git tag release).
${MAKE} git-tag-release

print-announce: ## Print announce of new release.
@PYTHONWARNINGS=all $(PYTHON) scripts/internal/print_announce.py
@$(TEST_PREFIX) $(PYTHON) scripts/internal/print_announce.py

print-timeline: ## Print releases' timeline.
@PYTHONWARNINGS=all $(PYTHON) scripts/internal/print_timeline.py
@$(TEST_PREFIX) $(PYTHON) scripts/internal/print_timeline.py

check-manifest: ## Inspect MANIFEST.in file.
$(PYTHON) -m check_manifest -v $(ARGS)
Expand All @@ -245,11 +246,11 @@ grep-todos: ## Look for TODOs in the source files.

bench-oneshot: ## Benchmarks for oneshot() ctx manager (see #799).
${MAKE} install
PYTHONWARNINGS=all $(PYTHON) scripts/internal/bench_oneshot.py
$(TEST_PREFIX) $(PYTHON) scripts/internal/bench_oneshot.py

bench-oneshot-2: ## Same as above but using perf module (supposed to be more precise)
${MAKE} install
PYTHONWARNINGS=all $(PYTHON) scripts/internal/bench_oneshot_2.py
$(TEST_PREFIX) $(PYTHON) scripts/internal/bench_oneshot_2.py

check-broken-links: ## Look for broken links in source files.
git ls-files | xargs $(PYTHON) -Wa scripts/internal/check_broken_links.py
Expand Down
6 changes: 4 additions & 2 deletions psutil/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,10 @@ def __str__(self):


def _setup_tests():
os.environ['PSUTIL_TESTING'] = '1'
assert psutil._psplatform.cext.py_psutil_testing()
if 'PSUTIL_TESTING' not in os.environ:
os.environ['PSUTIL_TESTING'] = '1' # not guaranteed to work
if not psutil._psplatform.cext.py_psutil_testing():
raise AssertionError('PSUTIL_TESTING env var is not set')


def get_suite():
Expand Down

0 comments on commit ffde326

Please sign in to comment.