Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
-1 votes
3 answers
125 views

My class doesn't generate a Fibonacci sequence properly

I'm trying to make a class that generates a Fibonacci sequence. My two modules are below, the fibonacci.py module and the test_fibonacci.py module. The first two tests pass but the third one seems to ...
JSO's user avatar
  • 21
0 votes
1 answer
51 views

Is there a boilerplate template for a TDD approach in Django-Python

I’m working on a side a project while trying to discipline myself to get accustomed to the TDD approach in Django. I'm not sure why I’m running into this failed test (venv) osahenru@osahenru ~/D/q-4&...
osahenru's user avatar
1 vote
2 answers
162 views

Unittest in according to TDD on Palindrome

I'm student at QA and now I try to write a palindrome code in Python based on TDD and unittest. I tried to write the code and it is functional but it doesn't work in according to assertTrue, also I ...
SPGA's user avatar
  • 11
1 vote
0 answers
52 views

How would you develop a function for API response parsing using TDD?

I just read "Test Driven Development: By Example" by Kent Beck, and I am trying to apply it on my current project. Given an API response I need to extract information from it. API response ...
hardhypochondria's user avatar
0 votes
1 answer
237 views

Ignore the rest of a function after asserting that a function is called in python

In Python, we want to assert that a function is called when calling another function. However, we want to ignore the execution after calling the required function. This necessity appears when we don't ...
Mounir's user avatar
  • 17
0 votes
0 answers
86 views

Pytest - execute test case only if previous test case fails

I have two test cases test_A(a,b,c) and test_B(a,b,c) in a python file. I use parameterization ( metafunc.parametrize("a,b,c",[(a1,a2,a3),....(y1,y2,y3)]) to pass 6 set of parameters ...
yowaf21832's user avatar
1 vote
1 answer
76 views

What type of tests should I use for writing a test with TDD?

I come from a PHP (Laravel) background and have just switched to Python. I am a big fan of TDD and have previously been writing 'feature' tests. Now I am writing AWS Lambdas (which are making lots of ...
Mick's user avatar
  • 1,551
0 votes
2 answers
71 views

How to TDD with Internet-Dependency in Python?

I need to make sure that I have a function that can download zip files from a list of links and write the file into the "zip_files/" folder. I am dependent on the outside webpage for the ...
Martin Müsli's user avatar
1 vote
3 answers
82 views

TDD modifying my test to make my code pass

I'm learning Test Driven Development, i'm struggling a little bit, seems like my brain wants to build solution algorithm, and not the needed test to build my algorithm. I can barely formalize unit ...
jmnguye's user avatar
  • 437
1 vote
1 answer
2k views

pytest mark parametrize a fixture

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 ...
des224's user avatar
  • 139
0 votes
1 answer
152 views

Mocking calls to super class in python through

I am trying to mock the super class of a class with a setup similar to this: File parent.py class Parent: def write(self): *some code* File child.py class Child(Parent): def write(...
david's user avatar
  • 1
1 vote
1 answer
912 views

how can i write unit test for function that is making network request without changing it's interface?

I read that Unit tests run fast. If they don’t run fast, they aren’t unit tests. A test is not a unit test if 1. It talks to a database. 2. It communicates across a network. 3. It touches the file ...
Visrut's user avatar
  • 629
1 vote
2 answers
655 views

Testing Python methods call sequence in a multithreaded context

I need to check the sequence of calling of some methods of a class. I had this need while I was developing using TDD (test driven development), so when I was writing the test for method_1() I would ...
User051209's user avatar
  • 2,468
1 vote
1 answer
214 views

Select different dataset when testing | Separate test from production

This question is partly about how to test external dependencies (a.k.a. integration tests) and partly how to implement it with Python for SQL with BigQuery in specific. So answers only about 'This is ...
JeroenDV's user avatar
  • 135
0 votes
0 answers
682 views

How to test with pytest a function or method returning a function?

I want to test my code and one of the most important function return a function. I tried: import pytest from operator methodcaller from matplotlib import pyplot as plt import numpy as np def foo(info:...
Samuel Diop's user avatar
0 votes
2 answers
407 views

Error when reverse url with multiple arguments - Django

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, ...
Lucas VB's user avatar
0 votes
1 answer
300 views

Bringing together transformations in pandas and TDD practices

So I have read this article on pandas anti-patterns and in the article it mentions the following: when you want to apply a set of transformation to a dataframe, you should chain them: # Mutation - DON'...
Jzbach's user avatar
  • 368
0 votes
0 answers
220 views

How to functional test if tkinter bind works

I'm working on an application with the tkinter graphical user interface. With the MVC pattern. I am partially using TDD - I realize that it is unnecessary for GUI build part. However, I assume that I ...
kubablo's user avatar
  • 113
0 votes
0 answers
130 views

Pytest isn't running tests in this one Python file

I cannot get Pytest to test anything involving this code. It always says no tests ran when I use the code below. I'm trying to just get it to test and from there I can tinker with the rest, I'm just a ...
HyperionSmith's user avatar
5 votes
3 answers
3k views

Create non-existent functions by a single click in VS Code Python

Other IDE's like PyCharm, IntelliJ, etc. have a feature where if it finds a function being called that is undefined, you can right-click it and click 'create method' or something similar to ...
Zohair Ul Hasan's user avatar
1 vote
1 answer
1k views

pytest in VS Code: Point out test failures because of NotImplementedError

I am using pytest and Visual Studio Code for test-driven development of a Python library. Many functions have been drafted as stubs but not yet implemented, so they raise a NotImplementedError. ...
clstaudt's user avatar
  • 22.4k
28 votes
2 answers
19k views

What are the differences between unittest.mock, mock, mocker and pytest-mock?

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,...
Pritam Bohra's user avatar
  • 4,309
0 votes
1 answer
61 views

How to define a "limit test context" using TDD?

How to I can define the "limit context" of my tests? I say this because of mocks, where my service has many other libs integrated, like: rabbit-mq, redis, etc, and instances from some one ...
willteam's user avatar
  • 127
1 vote
0 answers
112 views

python unittest mocking class and inherit

Theres some class # logging.py class Logging: def debug(msg): print(msg) def error(msg): print(msg) # index.py from logging import Logging def run(): self.logger = Logging() logger....
양정훈's user avatar
  • 255
0 votes
1 answer
911 views

Writing unit tests for Python API rate limiter (TDD approach)

I'm trying to teach myself TDD as I've never learned it and am using a practice problem. The prompt was to create an API rate limiter that returns true or false once a given customerID has hit a ...
jemadd04's user avatar
0 votes
1 answer
38 views

python unittest methods which call other methods

implementing basic space geometry class Class Geometry(object): # radius is required and must be float def circleSurface(self, radius): if not isinstance(radius, float): ...
hewi's user avatar
  • 1,376
2 votes
2 answers
1k views

TDD in Python - should we test helper functions?

A bit of a theoretical question that comes up with Python, since we can access almost anything we want even if it is underscored to sign as something "private". def main_function(): ...
MattSom's user avatar
  • 2,357
2 votes
1 answer
1k views

Django TypeError: force_authenticate() missing 1 required positional argument: 'self'

Test case setUp() that first creates a user and the try's to force authenticate the user but a wired error occurs... TypeError: force_authenticate() missing 1 required positional argument: 'self' ...
Amir Rezazadeh's user avatar
1 vote
1 answer
960 views

Django get_user_model().objects.create() password is not getting hashed

I have a test case which first creates a user and then try's to authenticate the created user with Django authenticate() method but looks like password is not getting hashed and therefore it fails to ...
Amir Rezazadeh's user avatar
1 vote
1 answer
384 views

Testing Two Classes With Each Other in Pytest

I just started learning about writing unit tests with pytest but I cannot find anything about testing to check if 2 classes work properly together where one class takes the output of the second class, ...
Athena Wisdom's user avatar
0 votes
1 answer
195 views

Clarification of Test Driven Development in Python

I am wondering if I can get some clarification on TDD and just Testing in general. I'm using python to write my program, and pytest as my testing framework. So far, the way I have been doing it, ...
Aaron Thompson's user avatar
0 votes
2 answers
85 views

Should I pass an object into a constructor (if yes, how to handle tests ?)

Let's suppose I have a "HamburgerCooker" that is supposed to cook a burger, and which is constructed with a "Request" class. Let's say a "Request" object is constructed ...
Jafty's user avatar
  • 1
1 vote
1 answer
55 views

How to write test for API views which create multiple DB objects on single request?

There is transaction table in my database, i've API which create multiple transaction rows in database on single request, i've write code to test the API but somehow it fails following is my code Here ...
Jay Soni's user avatar
  • 531
0 votes
1 answer
149 views

unittest - making setUp() the single source of truth for test data and its effect on parallelized testing

As far as I know, using unittest in Python is done something like this - # test.py import unittest import math from my_math import do_math class test_do(unittest.TestCase): def test_first_case(...
Anirudh Rowjee's user avatar
0 votes
0 answers
111 views

How to write pure unittest in Django?

so my question is, how to write pure unit tests with Django? For exmaple I have this model: class Topic(models.Model): title = models.CharField(max_length=255, validators=[MinLengthValidator(5)]) ...
Piotr Kowalski's user avatar
1 vote
1 answer
878 views

update a mocked object in python

I have a mocked object created as follows: with patch('requests.get') as request: self.request = request self.request.session = MockSession() self.request.cookies = {} How can ...
systemdebt's user avatar
  • 4,921
0 votes
0 answers
777 views

django test client CRUD API, unit testing

I want to write pure unit tests for my CRUD APP in django. Everyone use django tests or pytests, but I am really confused. Should I use test client to testing eg. POST method? Unit tests should be ...
Piotr Kowalski's user avatar
0 votes
1 answer
581 views

Setting HttpReferrer In Unit Tests

In my view.py I have the following check on several consecutive pages: if(request.META.get('HTTP_REFERER') != request.build_absolute_uri(reverse('page1'))): return redirect('page1') This ...
horse's user avatar
  • 491
1 vote
0 answers
195 views

TDD/testing CSS and HTML

I am stuck at this point below: '''selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: .has-error''' I tried to find a solution related to ".has-error" in order to ...
Makobak232's user avatar
1 vote
1 answer
3k views

Check connection refused error after Selenium Chrome webdriver .get

I run Selenium 3.141 tests with Chrome WebDriver. If I forget to start web server, Chrome gives ERR_CONNECTION_REFUSED error. But .get method doesn't raise any exception as if page was successfully ...
Winand's user avatar
  • 2,413
3 votes
2 answers
4k views

How to TDD with pandas and pytest?

I have a Python script that consolidates reports by using Pandas all along in a sequence of DataFrame operations (drop, groupby, sum, etc). Let's say I start with a simple function that cleans all ...
staticdev's user avatar
  • 3,050
0 votes
1 answer
106 views

How to use pytest command for code optimization

So, I am new in TDD and I recently had technical interview about task assignment that I did earlier. In interview, interviewer run some pytest command that pointed out these two lines in my code that ...
sAm's user avatar
  • 673
1 vote
1 answer
635 views

Django.core.exceptions.ImproperlyConfigured: Error running functional_tests.py

django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings....
manish's user avatar
  • 302
1 vote
1 answer
197 views

How to test edit function on django? (error django.db.utils.IntegrityError: NOT NULL constraint failed)

i try to write code for editing records and its unit test. here is my code: test_view.py def test_edit_address(self): address1 = Address.objects.create(first_name='Edith', last_name='Star', ...
thenoirlatte's user avatar
0 votes
1 answer
1k views

Django rest framework unauthenticated user get request error in testing

I'm trying to test the get request on the url which requires user to be authenticated. If user is unauthenticated it must return HTTP_401 UNAUTHORIZED error as response status code. For that purpose i'...
Surya Bhusal's user avatar
7 votes
2 answers
10k views

pytest option to output print/logging statements from tested code

Is there an option in pytest where the code that is being tested outputs it's logging.info(...) messages to the console This would make developing my test cases much easier, as there is a lot of ...
Karun's user avatar
  • 621
1 vote
2 answers
2k views

Always getting this AssertionError: 302 != 200 : Couldn't retrieve content: Response code was 302 (expected 200)

I'm very new in django, and currently was following a tutorial and I was trying to test users are listed on user page. So I setup test_admin.py. And i get an AssertionError 302 != 200. Below are my ...
metalheadcoder's user avatar
1 vote
1 answer
269 views

Why does monkeypatch not recognize an assignment value in the constructor?

I'm practicing TDD and I'm fairly new at this. In my test case, I want to read from stdin and check if the output matches the input. For stdin I'd like to use a mock object. Therefore I used ...
Christian's user avatar
5 votes
1 answer
5k views

How can I use a Docker container as a virtualenv for running Python tests from my IDE?

Don't get me wrong, virtualenv (or pyenv) is a great tool, and the whole concept of virtual environments is a great improvement on developer environments, mitigating the whole Snowflake Server anti-...
Alvaro Cavalcanti's user avatar
0 votes
0 answers
274 views

Testing That File Was Uploaded in Django

I am writing some unit-tests for an app. One of the features of this app is that it allows the user to upload videos to the server (or S3, depending on the configuration). The difficulty I am having ...
MadPhysicist's user avatar
  • 5,801

1
2 3 4 5 6