Skip to content Skip to sidebar Skip to footer
Showing posts with the label Unit Testing

How To Mock A Socket Object Via The Mock Library

How to mock a TCPSocket wrapper for the socket from the Python's standard libary via the mock l… Read more How To Mock A Socket Object Via The Mock Library

How To Properly Unit Test Filenotfounderror

With the unittest module, how can I test FileNotFoundError is raised when opening a file as follows… Read more How To Properly Unit Test Filenotfounderror

How To Organize Python Test In A Way That I Can Run All Tests In A Single Command?

Currently my code is organized in the following tree structure: src/ module1.py module2.py … Read more How To Organize Python Test In A Way That I Can Run All Tests In A Single Command?

Double Parameterization

So I have a set of tests where I'd like to test multiple versions of a solution. Currently I ha… Read more Double Parameterization

How To Unit Test Time Based Functions Without Adding Parameters

I created a function that returns seconds left until the next occurrence of that time, but I came a… Read more How To Unit Test Time Based Functions Without Adding Parameters

Run Python Unit Test With Python 2.7 And 3.x

I run my python unit tests by executing my test file through the shell and invoking if __name__ == … Read more Run Python Unit Test With Python 2.7 And 3.x

Running Unit Tests In Parallel With Pytest?

How can I parallelize the execution of the unit tests written with pytest? Which tactics of paralle… Read more Running Unit Tests In Parallel With Pytest?

Pytest : Cannot Mock __init__ Of My Class

I am having a custom Db class, which has the basic operations. I am trying to write tests around it… Read more Pytest : Cannot Mock __init__ Of My Class

Flask Unittest For Post Method

I am writing a Flask unit test for a function that would return a render template. I tried few ways… Read more Flask Unittest For Post Method

Drop Into An Interactive Session To Examine A Failed Unit Test

I'd like to be able to enter an interactive session, preferably with IPython, if a unit test fa… Read more Drop Into An Interactive Session To Examine A Failed Unit Test

How Can I Test Whether My Code Is Throwing The Appropriate Argparse Exceptions?

From this great answer I learned to put argument parsing into its own function to simplify unit tes… Read more How Can I Test Whether My Code Is Throwing The Appropriate Argparse Exceptions?

How Can I Mock Any Function Which Is Not Being Called Directly?

TL;DR How can I patch or mock 'any functions that are not being called/used directly'? Scen… Read more How Can I Mock Any Function Which Is Not Being Called Directly?

Python Unittest: Fail Due To Import From Same Folder

the question seems pretty trivial, but I could not find a single answer to it online. Heres my setu… Read more Python Unittest: Fail Due To Import From Same Folder

How To Locally Unit Test Python 3 App Engine Application?

I have testbed setup locally to test python2.7 based app engine application. As part of the python3… Read more How To Locally Unit Test Python 3 App Engine Application?

Mock A Pyqt Method

I have an existing class which inherits from the PyQT5 classes QWidget and Ui_Dialog. I want to use… Read more Mock A Pyqt Method

Does Someone Have An Example Of Unit-testing A Soap Api With Python Zeep And Mock?

I'm building a Python app that accesses a 3rd party SOAP API with Python-zeep. I want to implem… Read more Does Someone Have An Example Of Unit-testing A Soap Api With Python Zeep And Mock?

How To Test If Email Was Sent After Executing Celery Task

I'm using Django 1.10 and Celery 4.1 I have a shared_task which sends an email to the user. # m… Read more How To Test If Email Was Sent After Executing Celery Task

Flask Unit Tests With Sqlalchemy And Postgresql Exhausts Db Connections

I'm running a suite of fairly straightforward test cases using Flask, SQLAlchemy, and PostgreSQ… Read more Flask Unit Tests With Sqlalchemy And Postgresql Exhausts Db Connections

Python Mock And Libraries That Are Not Installed

I am working on software for a robot, which is normally run on the Raspberry Pi. Let's consider… Read more Python Mock And Libraries That Are Not Installed

Does Pytest Parametrized Test Work With Unittest Class Based Tests?

I've been trying to add parametrized @pytest.mark.parametrize tests to a class based unittest. … Read more Does Pytest Parametrized Test Work With Unittest Class Based Tests?