Install ipython_pytest via PyPI

This commit is contained in:
Jerry Pussinen
2018-05-21 18:35:07 +02:00
parent 4643b4eeaf
commit 0d0c6e61ad
9 changed files with 28 additions and 229 deletions

View File

@@ -9,7 +9,7 @@
"# Let's make sure pytest and ipython_pytest plugin are installed\n",
"import sys\n",
"!{sys.executable} -m pip install pytest\n",
"!{sys.executable} -m pip install ../../../utils/ipython_pytest/"
"!{sys.executable} -m pip install ipython_pytest"
]
},
{

View File

@@ -9,7 +9,7 @@
"# Let's make sure pytest and ipython_pytest plugin are installed\n",
"import sys\n",
"!{sys.executable} -m pip install pytest\n",
"!{sys.executable} -m pip install ../../../utils/ipython_pytest/"
"!{sys.executable} -m pip install ipython_pytest"
]
},
{

View File

@@ -11854,7 +11854,7 @@ div#notebook {
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1"># Let&#39;s make sure pytest and ipython_pytest plugin are installed</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="o">!{</span>sys.executable<span class="o">}</span> -m pip install pytest
<span class="o">!{</span>sys.executable<span class="o">}</span> -m pip install ../../utils/ipython_pytest/
<span class="o">!{</span>sys.executable<span class="o">}</span> -m pip install ipython_pytest
</pre></div>
</div>
@@ -11872,26 +11872,13 @@ div#notebook {
<div class="output_subarea output_stream output_stdout output_text">
<pre>Requirement already satisfied: pytest in /Users/jerry/.virtualenvs/learn-python3/lib/python3.5/site-packages (3.5.0)
Requirement already satisfied: six&gt;=1.10.0 in /Users/jerry/.virtualenvs/learn-python3/lib/python3.5/site-packages (from pytest) (1.11.0)
Requirement already satisfied: setuptools in /Users/jerry/.virtualenvs/learn-python3/lib/python3.5/site-packages (from pytest) (39.0.1)
Requirement already satisfied: attrs&gt;=17.4.0 in /Users/jerry/.virtualenvs/learn-python3/lib/python3.5/site-packages (from pytest) (17.4.0)
Requirement already satisfied: more-itertools&gt;=4.0.0 in /Users/jerry/.virtualenvs/learn-python3/lib/python3.5/site-packages (from pytest) (4.1.0)
Requirement already satisfied: pluggy&lt;0.7,&gt;=0.5 in /Users/jerry/.virtualenvs/learn-python3/lib/python3.5/site-packages (from pytest) (0.6.0)
Requirement already satisfied: py&gt;=1.5.0 in /Users/jerry/.virtualenvs/learn-python3/lib/python3.5/site-packages (from pytest) (1.5.3)
<span class="ansi-yellow-fg">You are using pip version 10.0.0, however version 10.0.1 is available.
You should consider upgrading via the &#39;pip install --upgrade pip&#39; command.</span>
Processing /Users/jerry/github/jerry-git/learn-python3/utils/ipython_pytest
Building wheels for collected packages: ipython-pytest
Running setup.py bdist_wheel for ipython-pytest ... - done
Stored in directory: /private/var/folders/nk/wgt71p5s1_d1wssm881h7ykc0000gn/T/pip-ephem-wheel-cache-tfei96ba/wheels/cd/57/26/ee80676d18b225631db5c78e9ddda568e7d2abf6f03c97047a
Successfully built ipython-pytest
Installing collected packages: ipython-pytest
Found existing installation: ipython-pytest 0.0.1.dev0
Uninstalling ipython-pytest-0.0.1.dev0:
Successfully uninstalled ipython-pytest-0.0.1.dev0
Successfully installed ipython-pytest-0.0.1.dev0
<span class="ansi-yellow-fg">You are using pip version 10.0.0, however version 10.0.1 is available.
You should consider upgrading via the &#39;pip install --upgrade pip&#39; command.</span>
Requirement already satisfied: attrs&gt;=17.4.0 in /Users/jerry/.virtualenvs/learn-python3/lib/python3.5/site-packages (from pytest) (17.4.0)
Requirement already satisfied: six&gt;=1.10.0 in /Users/jerry/.virtualenvs/learn-python3/lib/python3.5/site-packages (from pytest) (1.11.0)
Requirement already satisfied: more-itertools&gt;=4.0.0 in /Users/jerry/.virtualenvs/learn-python3/lib/python3.5/site-packages (from pytest) (4.1.0)
Requirement already satisfied: setuptools in /Users/jerry/.virtualenvs/learn-python3/lib/python3.5/site-packages (from pytest) (39.0.1)
Requirement already satisfied: ipython_pytest in /Users/jerry/.virtualenvs/learn-python3/lib/python3.5/site-packages (0.0.1)
</pre>
</div>
</div>
@@ -11981,15 +11968,15 @@ def test_sum_of_three_numbers():
<div class="output_subarea output_stream output_stdout output_text">
<pre>=========================================================== test session starts ===========================================================
<pre>============================================================ test session starts ============================================================
platform darwin -- Python 3.5.4, pytest-3.5.0, py-1.5.3, pluggy-0.6.0
rootdir: /private/var/folders/nk/wgt71p5s1_d1wssm881h7ykc0000gn/T/tmpgm5fi86g, inifile:
rootdir: /private/var/folders/nk/wgt71p5s1_d1wssm881h7ykc0000gn/T/tmpy9z1rypm, inifile:
plugins: nbval-0.9.0
collected 1 item
_ipytesttmp.py . [100%]
======================================================== 1 passed in 0.02 seconds =========================================================
========================================================= 1 passed in 0.02 seconds ==========================================================
</pre>
</div>
</div>

View File

@@ -11811,7 +11811,7 @@ div#notebook {
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1"># Let&#39;s make sure pytest and ipython_pytest plugin are installed</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="o">!{</span>sys.executable<span class="o">}</span> -m pip install pytest
<span class="o">!{</span>sys.executable<span class="o">}</span> -m pip install ../../utils/ipython_pytest/
<span class="o">!{</span>sys.executable<span class="o">}</span> -m pip install ipython_pytest
</pre></div>
</div>
@@ -11829,26 +11829,13 @@ div#notebook {
<div class="output_subarea output_stream output_stdout output_text">
<pre>Requirement already satisfied: pytest in /Users/jerry/.virtualenvs/learn-python3/lib/python3.5/site-packages (3.5.0)
Requirement already satisfied: more-itertools&gt;=4.0.0 in /Users/jerry/.virtualenvs/learn-python3/lib/python3.5/site-packages (from pytest) (4.1.0)
Requirement already satisfied: py&gt;=1.5.0 in /Users/jerry/.virtualenvs/learn-python3/lib/python3.5/site-packages (from pytest) (1.5.3)
Requirement already satisfied: pluggy&lt;0.7,&gt;=0.5 in /Users/jerry/.virtualenvs/learn-python3/lib/python3.5/site-packages (from pytest) (0.6.0)
Requirement already satisfied: more-itertools&gt;=4.0.0 in /Users/jerry/.virtualenvs/learn-python3/lib/python3.5/site-packages (from pytest) (4.1.0)
Requirement already satisfied: setuptools in /Users/jerry/.virtualenvs/learn-python3/lib/python3.5/site-packages (from pytest) (39.0.1)
Requirement already satisfied: six&gt;=1.10.0 in /Users/jerry/.virtualenvs/learn-python3/lib/python3.5/site-packages (from pytest) (1.11.0)
Requirement already satisfied: attrs&gt;=17.4.0 in /Users/jerry/.virtualenvs/learn-python3/lib/python3.5/site-packages (from pytest) (17.4.0)
Requirement already satisfied: pluggy&lt;0.7,&gt;=0.5 in /Users/jerry/.virtualenvs/learn-python3/lib/python3.5/site-packages (from pytest) (0.6.0)
Requirement already satisfied: setuptools in /Users/jerry/.virtualenvs/learn-python3/lib/python3.5/site-packages (from pytest) (39.0.1)
<span class="ansi-yellow-fg">You are using pip version 10.0.0, however version 10.0.1 is available.
You should consider upgrading via the &#39;pip install --upgrade pip&#39; command.</span>
Processing /Users/jerry/github/jerry-git/learn-python3/utils/ipython_pytest
Building wheels for collected packages: ipython-pytest
Running setup.py bdist_wheel for ipython-pytest ... - done
Stored in directory: /private/var/folders/nk/wgt71p5s1_d1wssm881h7ykc0000gn/T/pip-ephem-wheel-cache-ksypg6cf/wheels/cd/57/26/ee80676d18b225631db5c78e9ddda568e7d2abf6f03c97047a
Successfully built ipython-pytest
Installing collected packages: ipython-pytest
Found existing installation: ipython-pytest 0.0.1.dev0
Uninstalling ipython-pytest-0.0.1.dev0:
Successfully uninstalled ipython-pytest-0.0.1.dev0
Successfully installed ipython-pytest-0.0.1.dev0
<span class="ansi-yellow-fg">You are using pip version 10.0.0, however version 10.0.1 is available.
You should consider upgrading via the &#39;pip install --upgrade pip&#39; command.</span>
Requirement already satisfied: ipython_pytest in /Users/jerry/.virtualenvs/learn-python3/lib/python3.5/site-packages (0.0.1)
</pre>
</div>
</div>
@@ -11959,15 +11946,15 @@ def test_increase_age_with_negative_number(default_person):
<div class="output_subarea output_stream output_stdout output_text">
<pre>=========================================================== test session starts ===========================================================
<pre>============================================================ test session starts ============================================================
platform darwin -- Python 3.5.4, pytest-3.5.0, py-1.5.3, pluggy-0.6.0
rootdir: /private/var/folders/nk/wgt71p5s1_d1wssm881h7ykc0000gn/T/tmpi20fl62u, inifile:
rootdir: /private/var/folders/nk/wgt71p5s1_d1wssm881h7ykc0000gn/T/tmpj71o38he, inifile:
plugins: nbval-0.9.0
collected 4 items
_ipytesttmp.py .... [100%]
======================================================== 4 passed in 0.03 seconds =========================================================
========================================================= 4 passed in 0.03 seconds ==========================================================
</pre>
</div>
</div>
@@ -12038,20 +12025,20 @@ def test_replace_names(original, new_name, expected):
<div class="output_subarea output_stream output_stdout output_text">
<pre>=========================================================== test session starts ===========================================================
<pre>============================================================ test session starts ============================================================
platform darwin -- Python 3.5.4, pytest-3.5.0, py-1.5.3, pluggy-0.6.0
rootdir: /private/var/folders/nk/wgt71p5s1_d1wssm881h7ykc0000gn/T/tmpevgtpxwb, inifile:
rootdir: /private/var/folders/nk/wgt71p5s1_d1wssm881h7ykc0000gn/T/tmp3bo6s4_6, inifile:
plugins: nbval-0.9.0
collected 3 items
_ipytesttmp.py ... [100%]
============================================================ warnings summary =============================================================
============================================================= warnings summary ==============================================================
None
Module already imported so cannot be rewritten: nbval
-- Docs: http://doc.pytest.org/en/latest/warnings.html
================================================== 3 passed, 1 warnings in 0.03 seconds ===================================================
=================================================== 3 passed, 1 warnings in 0.03 seconds ====================================================
</pre>
</div>
</div>

View File

@@ -54,7 +54,7 @@
"# Let's make sure pytest and ipython_pytest plugin are installed\n",
"import sys\n",
"!{sys.executable} -m pip install pytest\n",
"!{sys.executable} -m pip install ../../utils/ipython_pytest/"
"!{sys.executable} -m pip install ipython_pytest"
]
},
{

View File

@@ -16,7 +16,7 @@
"# Let's make sure pytest and ipython_pytest plugin are installed\n",
"import sys\n",
"!{sys.executable} -m pip install pytest\n",
"!{sys.executable} -m pip install ../../utils/ipython_pytest/"
"!{sys.executable} -m pip install ipython_pytest"
]
},
{

View File

@@ -1,129 +0,0 @@
ipython_pytest
--------------
This little IPython extension gives you the ability to
run tests using Pytest in an IPython Notebook.
The motivation for the extension was to make it possible to
demonstrate test-driven development using pytest in an IPython
notebook driven presentation.
This extension does not attempt to enable using notebooks as test
suites. The intention is also not to collect test results from
multiple cells, but to do separate test runs for cells in an
interactive presentation.
This extension attempts to achieve for pytest_ what the
`ipython_nose`_ extension does for nose_. Unfortunately it isn't able
to inject globals from the notebook environment into the test like the
``%%nose`` cell magic in `ipython_nose_`. Instead, in
``ipython_pytest``, all imports, constants and helper functions need
to be contained in the test cell itself.
.. _pytest: https://pytest.org/
.. _ipython_nose: https://github.com/taavi/ipython_nose/pull/11/files
.. _nose: https://nose.readthedocs.io/
Installation
------------
* Make sure your IPython Notebook server can import ``ipython_pytest.py`` (e.g.
copy it to a directory in your ``PYTHONPATH``, or modify ``PYTHONPATH``
before starting IPython Notebook). It's also probably sufficient to have
``ipython_pytest.py`` in the directory from which you run the notebook, e.g.::
$ ls
ipython_pytest.py
$ ipython notebook
* You can also install it in a virtualenv in developent mode::
$ cd ipython-pytest
$ pip install -e .
Usage
-----
* Add a cell containing::
%load_ext ipython_pytest
somewhere in your notebook.
* Write tests that conform to Pytest conventions, e.g.::
def test_arithmetic():
assert 1+1 == 2
* Add a cell consisting of::
%%pytest
def test_my_stuff():
assert 42 == 42
to your notebook and run that cell. That will discover your
``test_*`` functions, run them, and show console output from
Pytest.
* Pass standard Pytest arguments to the magic::
%%pytest --tb=short
Caveats
-------
* None of the objects defined in other cells of the notebook are available
in the test cell.
Authors
-------
* Antti Kaihola <antti dot kaihola at eniram dot fi>
Thanks to Taavi Burns for the idea in his ipython-nose package.
Get the code
------------
::
git clone https://github.com/akaihola/ipython_pytest.git
Copyright
---------
Copyright (c) 2016, Antti Kaihola.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
Neither the name of the developers nor the names of contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -1,29 +0,0 @@
import os
import shlex
import sys
from pathlib import Path
import tempfile
from IPython.core import magic
from pytest import main as pytest_main
TEST_MODULE_NAME = '_ipytesttmp'
def pytest(line, cell):
with tempfile.TemporaryDirectory() as root:
oldcwd = os.getcwd()
os.chdir(root)
tests_module_path = '{}.py'.format(TEST_MODULE_NAME)
try:
Path(tests_module_path).write_text(cell)
args = shlex.split(line)
os.environ['COLUMNS'] = '80'
pytest_main(args + [tests_module_path])
if TEST_MODULE_NAME in sys.modules:
del sys.modules[TEST_MODULE_NAME]
finally:
os.chdir(oldcwd)
def load_ipython_extension(ipython):
magic.register_cell_magic(pytest)

View File

@@ -1,17 +0,0 @@
from distutils.core import setup
with open('README.rst') as f:
long_description = f.read()
setup(
name='ipython_pytest',
version='0.0.1.dev',
author='Antti Kaihola <antti dot kaihola at eniram dot fi>',
py_modules=['ipython_pytest'],
url='https://github.com/akaihola/ipython_pytest',
license='README.rst',
description='IPython extension to run pytest for the current cell.',
long_description=long_description,
)