pytest

Switched from WSGI to ASGI for Django Channels and now CircleCI throws "corrupted double-linked list" even though tests pass

Switched from WSGI to ASGI for Django Channels and now CircleCI throws "corrupted double-linked list" even though tests pass Question: I’ve been working on a project which requires WebSockets. The platform is built with Django and was running the WSGI server gunicorn. We decided to implement WebSockets using Django Channels. I set everything up including …

Total answers: 1

In Pytest, Is there a way to "mock" or prevent something from happening while collecting test?

In Pytest, Is there a way to "mock" or prevent something from happening while collecting test? Question: So assume the allowing : # services/foo.py from apps.bar import BarClass static_foos = BarClass().get_statics() class FooService() : …. and test code looking like : # tests/test_foo.py from services.foo import FooService def test_foo_something() : assert FooService.something() == True So …

Total answers: 2

pytest mark parametrize a fixture

pytest mark parametrize a fixture Question: I want to test a function get_xyz(a, b, foo), where foo is a class. A foo_fixture is defined in a conftest.py like so: @pytest.fixture() def foo_fixture(): return Foo() The fixture simply returns a new instance of a class Foo. How would I parametrize this foo_fixture as an argument to …

Total answers: 1

Mocking datetime.now using pytest-mock

Mocking datetime.now using pytest-mock Question: I have a function func_to_mock in module module_to_mock.py. My unit test is located in test_func_to_mock.py I am trying to mock datetime.datetime.now, however, I am struggling. I get the error TypeError: cannot set ‘now’ attribute of immutable type ‘datetime.datetime’. What am I missing here? module_to_mock.py: # module_to_mock.py import datetime def func_to_mock() …

Total answers: 1

Is it possible to put common checks for tests separately in pytest?

Is it possible to put common checks for tests separately in pytest? Question: I have a lot of negative tests with step that checks there had no effect to my system. To make sure that, added time.sleep() and then checks the system. Example: import pytest import time class TestIncorrect: def test_incorrect_table(): print("Step 1:") print("Do something …

Total answers: 1

I want to turn off output in pytest console

I want to turn off output in pytest console Question: I want to turn off output in Pytest console, so i can see only my logs I tried pytest -x -s -tb=no but its not exactly what i want I want to get rid of this output ======================================================== test session starts ========================================================= platform win32 — …

Total answers: 1

pytest!! Path setting doesn't work : –json-report-file= path

pytest!! Path setting doesn't work : –json-report-file= path Question: I am saving the report via -json-report. However, I want to save it to the desired path, but it is not saved. refer to the page https://pypi.org/project/pytest-json-report/ file tree I want to save it as a file named ‘report.json’ in the ‘Reports’folder. The test runs in …

Total answers: 1

Same dict variable value updated between tests in pytest

Same dict variable value updated between tests in pytest Question: I have 2 tests that use the same dict for data. But when I update something in 1 test that will affect the second test. I want them to be independent. data.py a = {"data": {‘data1’: ‘mydata’, ‘data2’: ‘mydata2’ } } test_mytest.py from data import …

Total answers: 1

Python unittest – assert called with is not working

Python unittest – assert called with is not working Question: i do a gitlab api call to a put_request and for my test I want to mock this call and assert if this call was called with the specific input. The problem is I do two put requests in my question with different input. This …

Total answers: 1