Skip to main content

All Questions

Tagged with
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 ...
nobody's user avatar
  • 300
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 ...
m3ta's user avatar
  • 301
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 ...
Achim's user avatar
  • 15.6k
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. ...
kev's user avatar
  • 9,427
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 ...
Priyeshj's user avatar
  • 1,335
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 ...
Mad Physicist's user avatar
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\...
Hybrid's user avatar
  • 7,011
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 ...
JBSnorro's user avatar
  • 6,528
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(): ...
A. Sarid's user avatar
  • 3,996
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 ...
Jorge Leitao's user avatar
  • 19.8k
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 ...
fmoor's user avatar
  • 349
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....
Arseni Mourzenko's user avatar
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 ...
m3hughes's user avatar
  • 247
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 ...
stawek's user avatar
  • 277
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 ./...
domke89's user avatar
  • 61

15 30 50 per page
1
2 3 4 5
74