All Questions
133
questions
0
votes
1
answer
59
views
pytest fixtures in nested Classes
I have written the following testcase using pytest.
import pytest
data_arg = ["arg1", "arg2"]
class TestParentClass1:
@pytest.fixture(scope="class", params=data_arg,...
1
vote
1
answer
49
views
Increasing test coverage for files I didn't write
I have written a python program that calculates various statistical values of a given list of integers and the range of values. Now, I am trying to write a test file for the program that can achieve &...
0
votes
3
answers
55
views
Pytest: When writing many assert statements in the same test function, some of it fails, but how to know which assert statement/s is causing failure?
Test file :
from RansomNote import Solution
def test_canConstruct():
sol = Solution()
assert sol.canConstruct('aa', 'aab') == True
assert sol.canConstruct('xx','aaabc') == True
assert ...
0
votes
2
answers
40
views
Mock from unittest not passed to Django view
def test_student_get(admin_user, some_model_fixture):
client = Client()
request_with_cookies = set_cookie(client, admin_user[0])
with patch('django.shortcuts.get_object_or_404') as ...
1
vote
0
answers
55
views
Python unittest/pytest tests priority
i have many unittests in my project each independent from another, however i would like to run the tests in parallel on several cores and in order to get the most out of it, it's necessary that the ...
1
vote
1
answer
36
views
Python ModuleNotFoundError when running tests
I have a Python program that runs correctly as expected, but for some reason I am not able to execute the tests.
In the folder hierarchy, tests is a sibling folder of src and the error I got when ...
0
votes
0
answers
44
views
Using pytest for OOPS where one class calls another and calls another
I am a noob at writing unit testing and I have not been able to find the answer anywhere for the following purpose
class xLoader:
def __init__(self, config, request_id,logger, mongo_obj,data_in):
...
1
vote
0
answers
33
views
Is it problematic to write tests for my lexer and then use that lexer to generate data for tests for my parser?
I'm writing a small transpiler. I've written extensive tests for my lexer. But writing tests for my parser is much more difficult because the parser needs to take in a List[Token] while the lexer ...
0
votes
1
answer
91
views
Test a function called in else condition
I have written a code where I am calling a function in the else case which returns a string. I have mocked it and asserted it to be called once. But this is failing for some reason. This decreases my ...
0
votes
2
answers
42
views
How do I mock a function called inside the function that I am testing?
My file structure is like this:
pytests/
├── moduleA/
│ ├── functions/
│ │ └── process_moduleA.py
│ └── test_process_moduleA.py
└── utils/
└── archive.py
in process_moduleA, I have ...
1
vote
0
answers
55
views
Pytest freezes the console?
I have a python project and I installed pytest to test my code. But I have a problem when execute the command pytest tests, the console freezes and I have to kill it.
My pytest.ini is
[pytest]
...
1
vote
1
answer
329
views
Pytest Not Discovering Tests in Specified Paths with pyproject.toml Configuration
I'm currently working on a Python project and using pytest for testing. I have structured my project to include tests in separate directories, and I'm trying to use a pyproject.toml file to specify ...
1
vote
1
answer
52
views
Creating a test case for add user functionality for movie app
I'm trying to write a test case for the movie site that I'm creating. I want to test the add_user method. Each time I call add_user() from my test method, it is created a user in my SQLite db and then ...
1
vote
1
answer
77
views
Wrong filed value in pydantic model
This is my pydantic class
class UploadResult(BaseModel):
reference: str
tag_uid: Optional[int] = Field(default=None, alias="tagUid")
class Config:
...
0
votes
0
answers
458
views
Can I write behavioural unit tests using "Given-When-Then" in Pytest (Python)?
We currently have many unit tests in Python and we're using Pytest. Ideally I'd like to stay with Pytest as that's what the company has elected to be their testing framework of choice. I wonder if ...