Questions tagged [pytest]

For questions about the pytest Python testing tool. Please also add the [python] tag for questions tagged with [pytest].

pytest is a mature, fully featured testing tool that simplifies the testing experience, which:

  • Provides no-boilerplate testing.
  • Supports functional testing and complex test setups.
  • Integrates many common testing methods.
  • Offers extensive plugin and customization system.

Be sure to check the Getting Started docs to see how easy it is to get running with pytest. The docs are comprehensive and development is open to contributions.

9822 questions
4
votes
1 answer

Django Channels Postgres InterfaceError: connection already closed

I can't seem to wrap my head around the issue here. I'm writing tests for my Channel Consumers following the description in the docs. I'd normally use the Django default unittest but since Channels requires using pytest, I'm using it but will still…
Ken4scholars
  • 6,076
  • 2
  • 21
  • 38
4
votes
1 answer

Gitlab CI variable, option with quotes

I have the following gitab-ci.yml file: stages: - tests .test: &test_job image: name: test.com/test:latest entrypoint: [""] script: - py.test /test -v $EXTRA_OPTIONS testing: variables: EXTRA_OPTIONS: -m "not…
Laser
  • 6,652
  • 8
  • 54
  • 85
4
votes
2 answers

How can we accept multiple values for one command line option in pytest

I would want the user to be able to pass multiple values to one command line argument. For example, if the contents of my contest.py has: parser.addoption("--url", action="store") Then I want the user to be able to do this: python -m pytest…
Rajat Bhardwaj
  • 129
  • 1
  • 11
4
votes
1 answer

Failure on unit tests with pytest, tornado and aiopg, any query fail

I've a REST API running on Python 3.7 + Tornado 5, with postgresql as database, using aiopg with SQLAlchemy core (via the aiopg.sa binding). For the unit tests, I use py.test with pytest-tornado. All the tests go ok as soon as no query to the…
Alberto
  • 687
  • 6
  • 21
4
votes
0 answers

numba raises performance warning when using @, eventhough array are contiguous

I do a simple dot product between a column of a Fortran array, and a line of a C array (so both are contiguous in memory). import numpy as np from numba import njit @njit def do_dot(): X = np.asfortranarray(np.ones((3, 4))) B =…
P. Camilleri
  • 12,664
  • 7
  • 41
  • 76
4
votes
1 answer

pipfile editable package location

I'm able to have the source files I'm working on installed to an editable package directory following the instructions here. So my pipenv looks like [dev-packages] pytest = "*" my-package= {editable = true, path = "."} This allows me to run pipenv…
Oliver Shaw
  • 5,235
  • 4
  • 26
  • 35
4
votes
2 answers

Running multiple test files from one test.py file through python Pytest

I have multiple test files in the test folder. The structure is similar to something like this: /test ----test_abc.py ----test_bcd.py ----test_cde.py ----conftest.py The conftest.py contains all the spark context initialization which is necessary…
talkdatatome
  • 614
  • 1
  • 10
  • 17
4
votes
1 answer

Output ASCII art to console on succesfull pytest run

I'm using pytest to run tests in Django project. I'm using pytest.ini where DJANGO_SETTINGS_MODULE is defined, so I run tests with just: pytest Now, I want to add some ASCII art to the console output if the test run is successful. I know I can…
ozren1983
  • 1,891
  • 1
  • 16
  • 34
4
votes
1 answer

Pytest and database cleanup before running tests

i am using Flask to build a web service and pytest for testing i am using pytest fixtures to set up and tear down the test resources but i need to test a POST endpoint that will create some records in the database How do we clean up these records ?
4
votes
1 answer

Mocking in Robot Framework

I am exploring the use of Robot Framework for writing unit tests in Python. We currently have some pre-existing unit tests that were developed using pytest. The unit-tests mock certain functionalities using the mock.patch method (such as connecting…
4
votes
1 answer

How to mock/patch whole class?

I have following code: pkg1/mock_class.py: class A: def ma(self): print(' class_A') class B: def __init__(self): self.var = 'vvv' def mb(self): a = A() print('class_B') a.ma() and test…
Jan Sakalos
  • 143
  • 2
  • 11
4
votes
2 answers

How to assert lists with pytest in a stable way?

After migrating a Python application from 2.6 to 2.7 I have learned from my pytest results that the order of a list has changed. The content of the list is the result of a third party openLDAP library. This is the list in Python 2.6: assert ['1',…
admirableadmin
  • 2,669
  • 1
  • 24
  • 41
4
votes
2 answers

Pytest Xdist parallel execution, prevent recreating the database

I'm trying to speed up the Selenium tests in my python Django web application by using parallel execution of 4 threads (-n=4) Of the first 4 tests, 3 give the following error: [test setup] [Test Error Output] Got an error creating the test database:…
Cloud
  • 458
  • 1
  • 13
  • 34
4
votes
2 answers

How can I make test data files accessible to pytest tests when run with tox?

I want to run a test for a function which accepts a Path to a file as input via an argument: function(some_path_to_file) via tox. The file I want to pass to the function cannot be created temporarily during test setup (what I usually do via pytests…
thinwybk
  • 4,193
  • 2
  • 40
  • 76
4
votes
2 answers

Pytest not selecting all tests from directory

I'm trying to set up a continious integration for my GitLab project for the first time and I am struggling to get the 'test' stage working. Right now I have my test subfolder and 2 almost identical tests in it that should pass. As I understand…
Andry
  • 339
  • 7
  • 23
1 2 3
99
100