From da8fd7e44675d0287c4095ea63e6bf56913dbfb3 Mon Sep 17 00:00:00 2001 From: Prabhu Ramachandran Date: Tue, 16 Apr 2019 17:51:26 +0530 Subject: Reorganize the pytest slides. --- testing/macros.tex | 7 ++-- testing/pytest.tex | 109 ++++++++++++++++++++++++++++++++--------------------- 2 files changed, 69 insertions(+), 47 deletions(-) (limited to 'testing') diff --git a/testing/macros.tex b/testing/macros.tex index 500912c..b5d16e3 100644 --- a/testing/macros.tex +++ b/testing/macros.tex @@ -2,9 +2,9 @@ % Modified from: generic-ornate-15min-45min.de.tex \mode { - \usetheme{Warsaw} + \usetheme{Madrid} \useoutertheme{infolines} - \setbeamercovered{transparent} + \setbeamercovered{invisible} } \usepackage[english]{babel} @@ -41,9 +41,10 @@ \newcommand{\typ}[1]{\textbf{\texttt{{#1}}}} - \newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} } +\newcommand{\py}[1]{\lstinline{#1}} + %%% This is from Fernando's setup. % \usepackage{color} % \definecolor{orange}{cmyk}{0,0.4,0.8,0.2} diff --git a/testing/pytest.tex b/testing/pytest.tex index c04d77d..31228b7 100644 --- a/testing/pytest.tex +++ b/testing/pytest.tex @@ -36,8 +36,8 @@ \begin{itemize} \item Write your code using the TDD paradigm \item Use the \typ{pytest} module to test your code - \item Run your tests on \url{travis-ci.org} \item Look at test coverage of your code + \item Run your tests on \url{travis-ci.org} \item Look at automatic coverage with \url{codecov.io} \end{itemize} \end{frame} @@ -166,7 +166,7 @@ test_gcd() def gcd(a, b): pass \end{lstlisting} - \item Written just, so that the tests can run + \item Written just so that the tests can run \item Obviously, the tests are going to fail \end{itemize} \end{frame} @@ -267,7 +267,7 @@ def gcd(a, b): \frametitle{Document \texttt{gcd}} \begin{itemize} \item Undocumented function is as good as unusable - \item Let's add a docstring \& We have our first test! + \item Let's add a docstring \end{itemize} \end{frame} \begin{frame}[fragile] @@ -555,6 +555,68 @@ class TestClass: \end{frame} +\section{Coverage} + +\begin{frame} + \Large + \begin{quote} + If you can't measure it, you can't improve it. + + \vspace*{0.5in} + \hfill - Peter Drucker + \end{quote} +\end{frame} + +\begin{frame} + \frametitle{Coverage of tests} + \begin{itemize} + \item Assess the amount of code that is covered by testing + \item \url{coverage.readthedocs.io} + \item \typ{pip install coverage} + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Using coverage} + \begin{lstlisting} +$ coverage run -m pytest my_package +$ coverage report +$ coverage html + \end{lstlisting}%$ +\end{frame} + +\begin{frame}[fragile] + \frametitle{Narrowing the source to look at} + \begin{lstlisting} +$ coverage run --source . \ + -m pytest my_package +$ coverage report +$ coverage html + \end{lstlisting}%$ +\end{frame} + +\begin{frame}[fragile] + \frametitle{Using a \texttt{.coveragerc}} + Create a \typ{.coveragerc} + \begin{lstlisting} +[run] +source = . +branch = True +omit = */tests/* + \end{lstlisting} +\end{frame} + +\begin{frame}[fragile,fragile] + \frametitle{Using \texttt{pytest-cov}} + \begin{itemize} + \item \typ{pytest-cov}, \url{https://pytest-cov.rtfd.io/} + \item Integrates directly with \typ{pytest} + \end{itemize} +\begin{lstlisting} +$ pytest --cov=myproj tests/ +\end{lstlisting} +\end{frame} + \section{Travis-CI} @@ -618,47 +680,6 @@ script: \end{frame} -\section{Coverage} - -\begin{frame} - \frametitle{Coverage of tests} - \begin{itemize} - \item Assess the amount of code that is covered by testing - \item \url{coverage.readthedocs.io} - \item \typ{pip install coverage} - \end{itemize} -\end{frame} - -\begin{frame}[fragile] - \frametitle{Using coverage} - \begin{lstlisting} -$ coverage run -m pytest my_package -$ coverage report -$ coverage html - \end{lstlisting}%$ -\end{frame} - -\begin{frame}[fragile] - \frametitle{Narrowing the source to look at} - \begin{lstlisting} -$ coverage run --source . \ - -m pytest my_package -$ coverage report -$ coverage html - \end{lstlisting}%$ -\end{frame} - -\begin{frame}[fragile] - \frametitle{Using a \texttt{.coveragerc}} - Create a \typ{.coveragerc} - \begin{lstlisting} -[run] -source = . -branch = True -omit = */tests/* - \end{lstlisting} -\end{frame} - \section{Codecov} -- cgit