All Questions
1,107
questions with no upvoted or accepted answers
12
votes
4
answers
2k
views
How to patch/mock import?
I'm writing tests for airflow dag and running into issue mocking/patching the dag.
# dag.py
from airflow.models import Variable
ENVIRONMENT = Variable.get("environment")
# test_dag.py
import dag
...
12
votes
0
answers
3k
views
Using Mocks inside Doctests?
I am using doctests. I am wondering what is the correct way to doctest a function that performs an external action (e.g. sends email, connects to a server, etc)? Using Mock seems like the answer but ...
10
votes
1
answer
1k
views
Code coverage for Jinja2 templates
I have a Pyramid web application which uses Jinja2 as template engine. It is tested using the Pyramid testing helpers together with py.test and the coverage plugin. But coverage works only for my ...
8
votes
1
answer
3k
views
Django can't flush database during tests
When trying to run my tests (python manage.py test) I am getting:
CommandError: Database test_db couldn't be flushed. Possible reasons:
* The database isn't running or isn't configured correctly.
...
8
votes
0
answers
478
views
How can I write tests to make sure celery tasks go into the right queue
Due to a complicated callback/chaining setup some tasks in our infrastructure seem to be going to queues that they were not assigned to. So I want to write automated tests to make sure that the celery ...
6
votes
1
answer
2k
views
pytest fixture and test both dependent on another fixture
I have a pair of fixtures for testing a function with x-y inputs. One generates the x-values, the other the y-values. The test depends on both. The y-values depend on the x-values as well. Here is a ...
6
votes
1
answer
3k
views
Django Test Error "Permission denied to create database" - Using Heroku Postgres
I am trying to do do a simple Django test using a tests.py file in a Django App directory (mysite/polls/tests.py), but every time I run 'python manage.py test polls', I get the error:
C:\Python27\...
5
votes
1
answer
1k
views
How to prevent vscode/ms-python from clearing test results?
The results of python tests are cached for only a short time in the VSCode MS python extension.
Whether they succeeded or failed is only cached for a short while, and then they revert back to question ...
5
votes
1
answer
724
views
Using a fixture inside pytest.mark.parametrize
Say I have a test function that takes a parametrize record as a dict, where one of its values is a fixture which is already defined.
For example, we have a fixture:
@pytest.fixture
def a_value():
...
5
votes
0
answers
858
views
Remove warnings and logging in minimal pyspark unit test
I am writing a set of unit tests for some library that depends and uses PySpark. For that, I am using something like this:
import unittest
import pyspark
from pyspark.sql.types import Row
class ...
5
votes
0
answers
3k
views
Testing that Django templates render correctly
I have an index.html that includes a nav.html which has a url tag that points to a rout name that doesn't exist. When I run the index view test the response code is 200 and the test passes. If I ...
5
votes
0
answers
1k
views
How do I know that the Flask application is ready to process the requests without actually polling it?
During a smoke test, I want to ensure that a Flask application is handling correctly a few basic requests. This involves starting the Flask application asynchronously:
class TestSmoke(unittest....
5
votes
0
answers
2k
views
How to properly test C API from python, the C API returns return codes as errors
My Setup
I am testing functions in a C library using pytest and ctypes from Python. Each function in the C library calls a function on an embedded linux PCI board, the C library functions then return ...
5
votes
3
answers
3k
views
How to call method on every py.test assertion failure?
Background:
I'm using py.test together with pytest-selenium, now I would like to take a screenshot of page when assertion fails.
Currently I have defined small helper method in my base page object ...
4
votes
0
answers
369
views
Generate a single report from multiple test stages in .gitlab-ci.yml
If there exist multiple test scripts in a .gitlab-ci.yml file, for example:
.run_warehouse_tests: &run_warehouse_tests |
echo "Running tests for Warehouse"
python -m pytest --durations=0 ./...