<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>pytest Archives - Creatronix</title>
	<atom:link href="https://creatronix.de/tag/pytest/feed/" rel="self" type="application/rss+xml" />
	<link>https://creatronix.de/tag/pytest/</link>
	<description>My adventures in code &#38; business</description>
	<lastBuildDate>Tue, 23 Dec 2025 08:53:33 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.1</generator>
	<item>
		<title>Python Tips &#038; Tricks for Junior Developers</title>
		<link>https://creatronix.de/python-tips-tricks-for-junior-developers/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Mon, 12 Sep 2022 16:40:14 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[devops]]></category>
		<category><![CDATA[hamcrest]]></category>
		<category><![CDATA[init]]></category>
		<category><![CDATA[juniordeveloper]]></category>
		<category><![CDATA[link sollection]]></category>
		<category><![CDATA[linksammlung]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[pbr]]></category>
		<category><![CDATA[pytest]]></category>
		<category><![CDATA[python tips]]></category>
		<category><![CDATA[tox]]></category>
		<guid isPermaLink="false">https://creatronix.de/?p=5915</guid>

					<description><![CDATA[<p>Motivation Learning the programming language Python is easy but becoming a proficient developer can be quite cumbersome: Python has a complex ecosystem of package / dependency management, some finicky language details and of course you should learn some tricks of the trade as well. So here is the place to start your journey into the&#8230;</p>
<p>The post <a href="https://creatronix.de/python-tips-tricks-for-junior-developers/">Python Tips &#038; Tricks for Junior Developers</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Motivation</h2>
<p>Learning the programming language Python is easy but becoming a proficient developer can be quite cumbersome:</p>
<p>Python has a complex ecosystem of package / dependency management, some finicky language details and of course you should learn some tricks of the trade as well.</p>
<p>So here is the place to start your journey into the world full of Python</p>
<h2>Before you start</h2>
<p>When you start a new project it&#8217;s good to think about the structure before you start to code</p>
<p><a href="https://creatronix.de/how-to-structure-your-python-project/">How to structure your Python project</a><a href="https://creatronix.de/how-to-write-your-init-py/"></a></p>
<p><a href="https://creatronix.de/autarke-skripte-in-python/">Autarke Skripte in Python</a></p>
<h2>Language Tips</h2>
<h3>Basic Features</h3>
<p><a href="https://creatronix.de/python-datetime-and-format/">Python datetime and format</a><a href="https://creatronix.de/f-strings-in-python/"></a></p>
<p><a href="https://creatronix.de/python-variable-length-arguments/">Python variable length arguments</a></p>
<p><a href="https://creatronix.de/running-external-commands-from-python/">Running external commands from Python</a></p>
<p><a href="https://creatronix.de/python-type-checking/">Python Type Checking</a></p>
<p><a href="https://creatronix.de/how-to-work-with-the-python-os-module/">How to work with the Python os module</a></p>
<p><a href="https://creatronix.de/how-to-use-the-sys-module-in-python/">How to use the sys module in Python</a></p>
<p><a href="https://creatronix.de/how-to-use-defaultdict/">How to use defaultdict</a></p>
<p><a href="https://creatronix.de/match-case-in-python-3-10/">match case in Python 3.10</a></p>
<p><a href="https://creatronix.de/so-funktionieren-structs-in-python/">So funktionieren structs in Python</a></p>
<h3>Program Input</h3>
<p><a href="https://creatronix.de/argparse/">Argparse</a></p>
<p><a href="https://creatronix.de/python-module-unicodecsv/">Python module unicodecsv</a></p>
<p><a href="https://creatronix.de/how-to-use-the-configparser-module/">How to use the configparser module</a></p>
<h3>File handling &amp; manipulation</h3>
<p><a href="https://creatronix.de/how-to-work-with-the-python-os-module/">How to work with the Python os module</a></p>
<p><a href="https://creatronix.de/getting-the-file-extension-from-a-file-path-in-python/">Getting the file extension from a file path in Python</a></p>
<p><a href="https://creatronix.de/how-to-use-glob-in-python/">How to use glob in Python</a></p>
<p><a href="https://creatronix.de/how-to-use-python-shutil/">How to use Python shutil</a></p>
<h3>More about structure</h3>
<p><a href="https://creatronix.de/how-to-write-your-init-py/"></a><a href="https://creatronix.de/how-to-write-your-init-py/">How to write your __init__.py</a></p>
<p><a href="https://creatronix.de/how-to-implement-python-decorators/">How to implement Python Decorators</a></p>
<p><a href="https://creatronix.de/how-to-implement-python-decorators-part-2/">How to implement Python Decorators &#8211; Part 2</a></p>
<h3>Classes &amp; Data Structures</h3>
<p><a href="https://creatronix.de/python-3-7-data-classes/">Python &#8211; data classes</a></p>
<p><a href="https://creatronix.de/difference-between-classmethod-and-staticmethod/">What&#8217;s the difference between classmethod and staticmethod in Python?</a></p>
<p><a href="https://creatronix.de/what-are-python-properties/">What are Python properties?</a></p>
<p><a href="https://creatronix.de/python-protocols/">Python Protocols</a></p>
<p><a href="https://creatronix.de/python3-chainmap/">Python3: ChainMap</a><a href="https://creatronix.de/python-module-unicodecsv/"></a></p>
<h2>Useful 3rd party packages</h2>
<p><a href="https://creatronix.de/how-to-use-google-translate-with-python/">How to use google translate with python</a></p>
<p><a href="https://creatronix.de/how-to-manipulate-nested-dictionaries-with-dotty/">How to manipulate nested dictionaries with dotty</a></p>
<p><a href="https://creatronix.de/how-to-store-sensible-data-in-a-env-file/">How to store sensible data in a .env file</a></p>
<p><a href="https://creatronix.de/overcoming-pyinstaller-pitfalls/">Overcoming PyInstaller Pitfalls</a></p>
<p><a href="https://creatronix.de/intro-to-opencv-with-python/">Intro to OpenCV with Python</a></p>
<p><a href="https://creatronix.de/pillow-how-to-convert-images-to-webp/">Pillow how to convert images to webp</a></p>
<p><a href="https://creatronix.de/how-to-create-youtube-thumbnails-pillow-tutorial/">How to create youtube thumbnails</a></p>
<h3>numpy</h3>
<p><a href="https://creatronix.de/linear-algebra-with-numpy-part-1/">Linear Algebra with numpy &#8211; Part 1</a></p>
<p><a href="https://creatronix.de/numpy-random-choice/">numpy random choice</a></p>
<p><a href="https://creatronix.de/numpy-linspace-function/">Numpy linspace function</a></p>
<h3>matplotlib</h3>
<p><a href="https://creatronix.de/introduction-to-matplotlib/">Introduction to matplotlib</a></p>
<p><a href="https://creatronix.de/introduction-to-matplotlib-part-2/">Introduction to matplotlib &#8211; Part 2</a></p>
<p><a href="https://creatronix.de/introduction-to-matplotlib-part-3/">Introduction to matplotlib &#8211; Part 3</a></p>
<p><a href="https://creatronix.de/scatterplot-with-matplotlib/">Scatterplot with matplotlib</a></p>
<h3>pandas</h3>
<p><a href="https://creatronix.de/introduction-to-pandas/">Introduction to Pandas</a></p>
<p><a href="https://creatronix.de/pandas-cheat-sheet/">Pandas Cheat Sheet</a></p>
<h3>JuPyteR Notebooks</h3>
<p><a href="https://creatronix.de/introduction-to-jupyter-notebook/">Introduction to Jupyter Notebook</a></p>
<p><a href="https://creatronix.de/visualize-geo-coordinates-with-ipyleaflet/">How to visualize geo coordinates with ipyleaflet</a></p>
<h2>Testing &amp; Quality</h2>
<p><a href="https://creatronix.de/software-testing-concepts/">Software Testing Concepts</a></p>
<p><a href="https://creatronix.de/pytest-tutorial-part-1/">pytest Tutorial &#8211; Part 1</a></p>
<p><a href="https://creatronix.de/pytest-tutorial-part-2/">pytest Tutorial &#8211; Part 2</a></p>
<p><a href="https://creatronix.de/pytest-tutorial-part-3/">pytest Tutorial &#8211; Part 3</a></p>
<p><a href="https://creatronix.de/how-to-let-test-cases-run-in-a-predefined-order/">How to let test cases run in a predefined order</a></p>
<p><a href="https://creatronix.de/python-package-parameterized/">Python Package parameterized</a></p>
<p><a href="https://creatronix.de/why-you-should-use-pyhamcrest-in-testing/">Why you should use PyHamcrest in testing</a></p>
<p><a href="https://creatronix.de/how-to-use-tox-to-test-your-code-on-multiple-platforms/">How to use tox to test your code on multiple platforms</a></p>
<p><a href="https://creatronix.de/how-to-add-travis-ci-to-your-github-project/">How to add Travis CI to your github project</a></p>
<p><a href="https://creatronix.de/how-to-use-the-timeit-module-to-check-performance-of-your-code/">How to use the timeit module to check performance of your code</a></p>
<h2>Logging</h2>
<p><a href="https://creatronix.de/logging-in-python-cheat-sheet/">Logging in Python &#8211; Cheat Sheet</a></p>
<h2>Packaging &amp; Dependencies</h2>
<p><a href="https://creatronix.de/python-pipfile-and-pipenv/">Python Pipfile and pipenv</a></p>
<p><a href="https://creatronix.de/pip-optional-dependencies/">pip optional dependencies</a></p>
<p><a href="https://creatronix.de/distributing-your-own-package-on-pypi/">Distributing your own package on PyPi</a></p>
<p><a href="https://creatronix.de/distributing-your-python-package-part2/">Distributing your own package on PyPi &#8211; Part 2</a></p>
<p><a href="https://creatronix.de/what-is-python-pbr/">What is python pbr?</a></p>
<p><a href="https://creatronix.de/visualizing-python-dependencies-with-pipdeptree/">Visualizing Python dependencies with pipdeptree</a></p>
<p>The post <a href="https://creatronix.de/python-tips-tricks-for-junior-developers/">Python Tips &#038; Tricks for Junior Developers</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>pytest Tutorial &#8211; Part 1</title>
		<link>https://creatronix.de/pytest-tutorial-part-1/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Wed, 08 Jan 2020 08:45:38 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[fixtures]]></category>
		<category><![CDATA[pytest]]></category>
		<guid isPermaLink="false">http://creatronix.de/?p=3001</guid>

					<description><![CDATA[<p>At PyConDE Berlin 2019 Florian Bruhin gave a really nice session about testing with pytest, which I try to recap here. Writing Tests If You want to work with pytest you can install it via: pip install pytest When you know basic python unittest fixtures, good news ahead: pytest is compatible and will run your&#8230;</p>
<p>The post <a href="https://creatronix.de/pytest-tutorial-part-1/">pytest Tutorial &#8211; Part 1</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>At <a href="https://creatronix.de/pyconde-berlin-2019/">PyConDE Berlin 2019</a> Florian Bruhin gave a really nice session about testing with pytest, which I try to recap here.</p>
<h2>Writing Tests</h2>
<p>If You want to work with pytest you can install it via:</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-bash" data-lang="Bash"><code>pip install pytest</code></pre>
</div>
<p>When you know basic python unittest fixtures, good news ahead:</p>
<p>pytest is compatible and will run your old unittest classes as well, but pytest doesn&#8217;t need to have a testclass derived from some subclass.</p>
<p><strong>It is sufficient to have a single python file which name starts with <em>test_</em> containing a function which name also starts with <em>test_</em></strong></p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-python" data-lang="Python"><code>def test_stuff():
    x = 5.0
    assert x == 5</code></pre>
</div>
<p>That&#8217;s all You need!</p>
<h2>Autodiscovery</h2>
<p>If you run pytest from the command line it will automatically discover tests which cohere to this naming convention like unittest -discover</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-bash" data-lang="Bash"><code>pytest</code></pre>
</div>
<h2>Select test cases</h2>
<p>You can specify the tests to be run by module::test_function or by module::test_class::test_method e.g.</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-bash" data-lang="Bash"><code>pytest test_sort_algortihms.py::TestSortAlgorithms::test_python_sorted</code></pre>
</div>
<p>As an alternative you can use the option -k &#8220;test_case_name&#8221; to glob testcases.</p>
<h2>Execution time</h2>
<p><span class="comment-copy">If you pass <code>--durations=0</code> execution time for all tests will be reported.</span></p>
<h2>Useful command line arguments</h2>
<p>When learning pytest, it is good to learn some command line flags as well</p>
<ul>
<li>-h : help</li>
<li>-k &#8220;&lt;name_of_test&gt;&#8221; : glob test name</li>
<li>-x : quit on first error</li>
<li>&#8211; -pdb : start debugger on error</li>
<li>-v : increase verbosity</li>
<li>-s : show print output</li>
<li>-rf : reason for failure</li>
<li>-rs : reason for skipping</li>
<li>-m &lt;marker_name&gt; : run only marked tests</li>
<li>&#8211;fixtures : show fixtures in modules</li>
</ul>
<h2>Configuration via file</h2>
<p>You can save your preferences for running pytest in a file called pytest.ini</p>
<pre>[pytest]
addopts = -x --durations=0 -vv</pre>
<h2>Understanding Fixtures</h2>
<p>Fixtures are pytest&#8217;s equivalent to setUp methods from unittest with the difference that you can define when they should be used.</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-python" data-lang="Python"><code>import pytest 

@pytest.fixture 
def some_value(): 
    return 42 

def test_function(some_value): 
    assert some_value == 42</code></pre>
</div>
<p>After declaring a fixture with decorator @pytest.fixture you can use this special function as a parameter to your test functions.</p>
<h3>Fixture scope</h3>
<p>Without any further definition a fixture function is called before every function it is used in. When You do some heavy lifting in a fixture and you want to reuse that you can specify the module scope so that the fixture function just runs once per module</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-python" data-lang="Python"><code>@pytest.fixture(scope="module")</code></pre>
</div>
<p>If you even want to instantiate a fixture once per session this is also possible with</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-python" data-lang="Python"><code>@pytest.fixture(scope="session")</code></pre>
</div>
<p>Next part <a href="https://creatronix.de/pytest-tutorial-part-2/">pytest Tutorial &#8211;  Part 2</a></p>
<p>&nbsp;</p>
<p>The post <a href="https://creatronix.de/pytest-tutorial-part-1/">pytest Tutorial &#8211; Part 1</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
