Pytest Installation: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Pytest =Overview= <font color=darkkhaki> This procedure worked for a virtual environment located with the project. Configured direnv to set...")
 
 
(4 intermediate revisions by the same user not shown)
Line 4: Line 4:
=Overview=
=Overview=


<font color=darkkhaki>
<code>pytest</code> is installed in a virtual environment and then used from that virtual environment.
This procedure worked for a virtual environment located with the project. Configured direnv to set PATH to give priority to the local virtual environment <code>pip</code>.


<font size=-1>
Add this to <code>requirements.txt</code>:
pip install -U pytest
</font>


pytest was installed in the local virtual environment.
<syntaxhighlight lang='py'>
</font>
pytest == 7.1.2
</syntaxhighlight>
 
Then
 
 
 
For your project, configure <code>direnv</code> to set PATH to give priority to your virtual environment <code>bin</code> directory. In <code>.envrc</code>:
 
<syntaxhighlight lang='bash'>
PATH_add "./src/main/python/venv/bin"
</syntaxhighlight>
 
Then install <code>pytest</code> with that <code>pip</code>:
 
<syntaxhighlight lang='bash'>
pip install -U pytest
</syntaxhighlight>
 
Given the <code>direnv</code> setup, <code>pytest</code> will automatically become available:
 
<syntaxhighlight lang='bash'>
which pytest
 
.../src/main/python/venv/bin/pytest
</syntaxhighlight>
 
=Check for pytest from Script=
<syntaxhighlight lang='bash'>
pytest --version 2>/dev/null 1>&2 || fail "pytest not installed, cannot execute python tests"
</syntaxhighlight>

Latest revision as of 20:52, 25 July 2023

Internal

Overview

pytest is installed in a virtual environment and then used from that virtual environment.

Add this to requirements.txt:

pytest == 7.1.2

Then


For your project, configure direnv to set PATH to give priority to your virtual environment bin directory. In .envrc:

PATH_add "./src/main/python/venv/bin"

Then install pytest with that pip:

pip install -U pytest

Given the direnv setup, pytest will automatically become available:

which pytest

.../src/main/python/venv/bin/pytest

Check for pytest from Script

pytest --version 2>/dev/null 1>&2 || fail "pytest not installed, cannot execute python tests"