Skip to content

Commit

Permalink
Merge 839e8a2 into 53fd469
Browse files Browse the repository at this point in the history
  • Loading branch information
fornellas committed Apr 14, 2020
2 parents 53fd469 + 839e8a2 commit 05de9af
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 19 deletions.
7 changes: 7 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[run]
parallel = True

[report]
precision = 2
fail_under = 92.31
include = testslide/*
11 changes: 7 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
dist/
MANIFEST
TestSlide.egg-info/
**/__pycache__/
**/*.pyc
**/__pycache__/
.coverage
.coverage.*.*.*
dist/
docs/_build/
htmlcov/
MANIFEST
TestSlide.egg-info/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ python:
install:
- make install_deps
script:
make test install_local
TESTSLIDE_FORMAT="progress" UNITTEST_VERBOSE="" make travis
52 changes: 40 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,54 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

TESTSLIDE_FORMAT?=documentation
UNITTEST_VERBOSE?=--verbose

.PHONY: all
all: test

.PHONY: coveralls
coveralls:
coveralls

.PHONY: travis
travis: test install_local coveralls

.PHONY: install_deps
install_deps:
pip install -e .[test,build]

.PHONY: flake8
flake8:
flake8 --select=F,C90 testslide/ tests/

.PHONY: black_check
black_check:
bash -c "if black --help &>/dev/null ; then exec black --check testslide/ tests/ ; fi"
black --check testslide/ tests/

.PHONY: coverage_erase
coverage_erase:
coverage erase

.PHONY: unittest_tests
unittest_tests:
python -m unittest discover --verbose --failfast -p '*_unittest.py'
unittest_tests: coverage_erase
coverage run -m unittest discover $(UNITTEST_VERBOSE) --failfast -p '*_unittest.py'

.PHONY: testslide_tests
testslide_tests:
python -m testslide.cli --show-testslide-stack-trace --fail-fast --fail-if-focused tests/*_testslide.py
testslide_tests: coverage_erase
coverage run -m testslide.cli --format $(TESTSLIDE_FORMAT) --show-testslide-stack-trace --fail-fast --fail-if-focused tests/*_testslide.py

.PHONY: coverage_combine
coverage_combine: unittest_tests testslide_tests
coverage combine

.PHONY: coverage_report
coverage_report: coverage_combine
coverage report

.PHONY: coverage_html
coverage_html: coverage_combine
coverage html

.PHONY: docs
docs:
Expand All @@ -30,17 +60,15 @@ docs:
sdist:
python setup.py sdist

.PHONY: test
test: unittest_tests testslide_tests black_check flake8 docs sdist

.PHONY: install_local
install_local:
pip install -e .
testslide --help

.PHONY: install_deps
install_deps:
pip install -e .[test,build]
.PHONY: test
test: unittest_tests testslide_tests coverage_report black_check flake8 docs sdist

.PHONY: clean
clean:
rm -rf dist/ MANIFEST TestSlide.egg-info/ */__pycache__/ */*.pyc docs/_build/
coverage erase
rm -rf dist/ MANIFEST TestSlide.egg-info/ */__pycache__/ */*.pyc docs/_build/ htmlcov/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# TestSlide: Fluent Python Testing

[![Build Status](https://travis-ci.com/facebookincubator/TestSlide.svg?branch=master)](https://travis-ci.com/facebookincubator/TestSlide)
[![Coverage Status](https://coveralls.io/repos/github/facebookincubator/TestSlide/badge.svg?branch=coverage)](https://coveralls.io/github/facebookincubator/TestSlide?branch=coverage)
[![Documentation Status](https://readthedocs.org/projects/testslide/badge/?version=master)](https://testslide.readthedocs.io/en/master/?badge=master)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![PyPI version](https://badge.fury.io/py/TestSlide.svg)](https://badge.fury.io/py/TestSlide)
Expand Down
20 changes: 20 additions & 0 deletions docs/test_runner/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,26 @@ Slow Imports Profiler

As projects grow with more dependencies, running a test for a few lines of code can take several seconds. This is often cause by time spent on importing dependencies, rather that the tests themselves. If you run your tests with ``--import-profiler $MS``, any imported module that took more that that the given amount of milliseconds will be reported in a nice and readable tree view. This helps you optimize your imports, so your unit tests can run faster. Frequently, the cause of slow imports is the construction of heavy objects at module level.

Code Coverage
-------------

`Coverage.py <https://coverage.readthedocs.io/en/coverage-5.1/>`_ integration is simple. Make sure your ``.coveragerc`` file has this set:

.. code-block:: ini
[run]
parallel = True
and then you can run all your tests and get a report like this

.. code-block:: shell
$ coverage erase
$ COVERAGE_PROCESS_START=.coveragerc testslide some.py tests.py
$ COVERAGE_PROCESS_START=.coveragerc testslide some_more_tests.py
$ coverage combine
$ coverage report
Tip: Automatic Test Execution
-----------------------------

Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
extras_require={
"build": [
"black",
"ipython",
"coverage",
"coveralls",
"flake8",
"ipython",
"sphinx",
"sphinx-autobuild",
"sphinx_rtd_theme",
Expand Down
4 changes: 3 additions & 1 deletion tests/cli_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class TestCliBase(unittest.TestCase):

def setUp(self):
self.argv = [self.SAMPLE_TESTS_PATH]
self.env = {}
self.env = {
"COVERAGE_PROCESS_START": ".coveragerc",
}
super(TestCliBase, self).setUp()

def run_testslide(
Expand Down
7 changes: 7 additions & 0 deletions testslide/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

import os

if "COVERAGE_PROCESS_START" in os.environ:
import coverage

coverage.process_startup()

from contextlib import contextmanager

import asyncio
Expand Down

0 comments on commit 05de9af

Please sign in to comment.