testing

Google Kickstart 2022 Problem Record Breaker Wrong Answer

Google Kickstart 2022 Problem Record Breaker Wrong Answer Question: Sorry for the formatting. New at posting questions I was practicing this problem asked in the last round of Google Kick Start 2020. The problem is called Record Breaker and is as follows: Isyana is given the number of visitors at her local theme park on …

Total answers: 1

Mocking a global variable in pytest

Mocking a global variable in pytest Question: how do you mock a global variable in pytest? Here is a pair of example files: File being tested, call it main.py: MY_GLOBAL = 1 def foo(): return MY_GLOBAL*2 def main() # some relevant invokation of foo somewhere here if __name__==’__main__’: main() File that is testing, call it …

Total answers: 2

Skipping specific parametrized pytests based on failure for specific parameters

Skipping specific parametrized pytests based on failure for specific parameters Question: I have some parametrized tests def test1(): #do test1 def test2(): #do test2 def test3(): #do test3 Each test is parametrized by @pytest.mark.parametrize(x) I would like to run these tests against test_data=[1,2,3,4] I have tried using pytest-depends @pytest.mark.depends(on=[‘test1’]) @pytest.mark.parametrize(x) However, I get that all …

Total answers: 1

Should I run tests during the docker build?

Should I run tests during the docker build? Question: I have a Dockerfile like this: FROM python:3.9 WORKDIR /app RUN apt-get update && apt-get upgrade -y RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python – ENV PATH /root/.local/bin:$PATH COPY pyproject.toml poetry.lock Makefile ./ COPY src ./src COPY tests ./tests RUN poetry install && poetry run pytest && …

Total answers: 2

Is there any library like arch unit for Django?

Is there any library like arch unit for Django? Question: I’ve been searching for a library or tool to test my Django project architecture, check the dependencies, layers, etc. like Arch Unit for Java. But until now, I didn’t find anything. I don’t even know if it’s viable doing these kinds of tests in Python/Django …

Total answers: 3

Requests-html can I get status codes of all requests (or selenium alternative)

Requests-html can I get status codes of all requests (or selenium alternative) Question: I have the following code: from requests_html import HTMLSession ses = HTMLSession() r = ses.get(MYURL) # start a headless chrome browser and load MYURL r.render(keep_page=True) # This will now ‘render’ the html page # which means like in a real browser trigger …

Total answers: 2

Test Pydantic settings in FastAPI

Test Pydantic settings in FastAPI Question: Suppose my main.py is like this (this is a simplified example, in my app I use an actual database and I have two different database URIs for development and testing): from fastapi import FastAPI from pydantic import BaseSettings app = FastAPI() class Settings(BaseSettings): ENVIRONMENT: str class Config: env_file = …

Total answers: 4

405 error when testing an authed django-rest-framework route

405 error when testing an authed django-rest-framework route Question: I’m testing a CreateAPIView with an APITestCase class. Things are working as expected as an anonymous user, but when I login() as a user, I get a 405 HttpResponseNotAllowed exception. I’m able to successfully create an object while authed as a user through the django-rest-framework web …

Total answers: 2