You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<title>1. Introduction: abstraction in mathematics and programming — Object oriented programming in Python for mathematicians 2020.0 documentation</title>
8
+
<title>1. Introduction: abstraction in mathematics and programming — Object oriented programming in Python for mathematicians 2021.0 documentation</title>
the practical details of including tests in your code here.</p>
638
638
<p>There are a number of Python packages which support code testing. The
639
639
concepts are largely similar so rather than get bogged down in the
640
-
details of multiple frameworks, we will introduce <aclass="reference external" href="https://docs.pytest.org/en/latest/index.html" title="(in pytest v6.3.0.dev88+gf6529fd3a)"><spanclass="xref std std-doc">pytest</span></a>, which is one of the most widely used.</p>
640
+
details of multiple frameworks, we will introduce <aclass="reference external" href="https://docs.pytest.org/en/latest/index.html" title="(in pytest v6.3.0.dev88+gf6529fd3a)"><spanclass="xref std std-doc">pytest</span></a>, which is one of the most widely used. Pytest is simply a Python
641
+
package, so you can install it into your current environment using:</p>
<h3><spanclass="section-number">2.7.1. </span>Pytest tests<aclass="headerlink" href="#pytest-tests" title="Permalink to this headline">¶</a></h3>
643
647
<p>A Pytest test is simply a function whose name starts with <codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">test_</span></code>. In
<h3><spanclass="section-number">2.7.3. </span>Additional useful pytest tricks<aclass="headerlink" href="#additional-useful-pytest-tricks" title="Permalink to this headline">¶</a></h3>
736
740
<p>It can be useful to run a specific test file, which is achieved simply by naming
737
-
that file as the argument to py.test. For example:</p>
<p>Often if one test fails then the same problem in your code will cause a whole
747
751
series of tests to fail, resulting in a very long list of error messages which
748
752
is hard to read. A useful tool in this circumstance is the <codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">-x</span></code> option, which
749
753
tells pytest to stop after the first test fail. For example:</p>
<p>Then push your code to GitHub and check that the tests pass there too.</p>
893
902
<divclass="admonition hint">
894
903
<pclass="admonition-title">Hint</p>
895
904
<p>The Python modulo operator is <codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">%</span></code>. For example:</p>
@@ -915,6 +924,9 @@ <h2><span class="section-number">2.10. </span>Exercises<a class="headerlink" hre
915
924
<p>Following <aclass="reference internal" href="#installable-packages"><spanclass="std std-numref">Section 2.6.2</span></a>, create a <codeclass="file docutils literal notranslate"><spanclass="pre">setup.py</span></code> file in
916
925
your exercise repository, so that the <codeclass="xref py py-mod docutils literal notranslate"><spanclass="pre">math_utils</span></code><aclass="reference internal" href="#term-package"><spanclass="xref std std-term">package</span></a> is
917
926
installable.</p>
927
+
<p>Pytest can’t easily test installability for you, so once you have managed to
928
+
install your package yourself, commit and push to github to check that the
929
+
tests there are also able to install your package.</p>
0 commit comments