tdd

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

Error when reverse url with multiple arguments – Django

Error when reverse url with multiple arguments – Django Question: I’m writing a test for an url, problem is it fails when I try to pass multiple arguments, here is some code: #test_urls.py from django.test import SimpleTestCase from django.urls import reverse, resolve from cardiotesting.views import * class TestUrls(SimpleTestCase): def test_new_cardio(id_patient, protocol): id_patient = ’05’ protocol …

Total answers: 2

unittest.mock vs mock vs mocker vs pytest-mock

unittest.mock vs mock vs mocker vs pytest-mock Question: I am new to Python development, I am writing test cases using pytest where I need to mock some behavior. Googling best mocking library for pytest, has only confused me. I have seen unittest.mock, mock, mocker and pytest-mock. Not really sure which one to use.Can someone please …

Total answers: 2

pytest to insert caplog fixture in test method

pytest to insert caplog fixture in test method Question: I have the following test class for pytest: class TestConnection(AsyncTestCase): ”’Integration test”’ @gen_test def test_connecting_to_server(self): ”’Connecting to the TCPserver”’ client = server = None try: sock, port = bind_unused_port() with NullContext(): server = EchoServer() server.add_socket(sock) client = IOStream(socket.socket()) #### HERE I WANT TO HAVE THE caplog …

Total answers: 1

How to Mock a user input in Python

How to Mock a user input in Python Question: I am currently trying to learn how to Unit Test with Python and was introduced to the concept of Mocking, I am a beginner Python developer hoping to learn the concepts of TDD alongside my development of Python skills. I am struggling to learn the concept …

Total answers: 3

Is there a python equivalent for RSpec to do TDD?

Is there a python equivalent for RSpec to do TDD? Question: I’m looking for a test framework like Ruby’s RSpec to do test driven development in Python. The advantage of a framework like RSpec is that it offers a DSL that lends itself well to TDD. First you describe the test in english, and then …

Total answers: 4

How do I run unittest on a Tkinter app?

How do I run unittest on a Tkinter app? Question: I’ve just begun learning about TDD, and I’m developing a program using a Tkinter GUI. The only problem is that once the .mainloop() method is called, the test suite hangs until the window is closed. Here is an example of my code: # server.py import …

Total answers: 4

Proper way to test Django signals

Proper way to test Django signals Question: I’m trying to test sent signal and it’s providing_args. Signal triggered inside contact_question_create view just after form submission. My TestCase is something like: def test_form_should_post_proper_data_via_signal(self): form_data = {‘name’: ‘Jan Nowak’} signals.question_posted.send(sender=’test’, form_data=form_data) @receiver(signals.question_posted, sender=’test’) def question_posted_listener(sender, form_data): self.name = form_data[‘name’] eq_(self.name, ‘Jan Nowak’) Is this the proper way …

Total answers: 7

Python library 'unittest': Generate multiple tests programmatically

Python library 'unittest': Generate multiple tests programmatically Question: Possible Duplicate: How do you generate dynamic (parameterized) unit tests in Python? I have a function to test, under_test, and a set of expected input/output pairs: [ (2, 332), (234, 99213), (9, 3), # … ] I would like each one of these input/output pairs to be …

Total answers: 6