pytest reports too much on assert failures

2024/10/10 0:22:47

Is there a way for pytest to only output a single line assert errors?

This problem arises when you have modules with asserts, If those asserts fails, it dumps the entire function that failed the asserts.

> assert r.status_code == 200, f"{idtest.tools.now()} wrong status code {r.status_code}: resp:{r.text}"
E AssertionError: 2019-06-11 12:41:17.239128 wrong status code 500: resp:{"timestamp":"2019-06-11T10:41:17.187+0000","status":500,"error":"Internal Server Error","message":"The user was not found","path":"/mid/business"}

In this case the idtest.testapi.midbusiness() is shown entirely in the pytest output.

Answer

Adjust the traceback print mode (--tb):

$ pytest --help--tb=style            traceback print mode (auto/long/short/line/native/no).

E.g. pytest --tb=no will not print any trace at all.

https://en.xdnf.cn/q/69959.html

Related Q&A

pulp.solvers.PulpSolverError: PuLP: cannot execute glpsol.exe

I am a newbie with python and optimization. I am getting some error, please help me resolve it. I tried running the below mentioned code in PyCharm where I am running Anaconda 3from pulp import * x = L…

Django urldecode in template file

is there any way do the urldecode in Django template file? Just opposite to urlencode or escapeI want to convert app%20llc to app llc

Structure accessible by attribute name or index options

I am very new to Python, and trying to figure out how to create an object that has values that are accessible either by attribute name, or by index. For example, the way os.stat() returns a stat_resul…

Loading data from Yahoo! Finance with pandas

I am working my way through Wes McKinneys book Python For Data Analysis and on page 139 under Correlation and Covariance, I am getting an error when I try to run his code to obtain data from Yahoo! Fin…

Run Multiple Instances of ChromeDriver

Using selenium and python I have several tests that need to run in parallel. To avoid using the same browser I added the parameter of using a specific profile directory and user data (see below). The p…

numpy 2d array max/argmax

I have a numpy matrix:>>> A = np.matrix(1 2 3; 5 1 6; 9 4 2) >>> A matrix([[1, 2, 3],[5, 1, 6],[9, 4, 2]])Id like to get the index of the maximum value in each row along with the valu…

How do I add a python script to the startup registry?

Im trying to make my python script run upon startup but I get the error message windowserror access denied, but I should be able to make programs start upon boot because teamviewer ( a third-party prog…

Python: How can I filter a n-nested dict of dicts by leaf value?

Ive got a dict that looks something like this:d = {Food: {Fruit : {Apples : {Golden Del. : [Yellow],Granny Smith : [Green],Fuji : [Red], },Cherries : [Red],Bananas : [Yellow],Grapes …

contour plot - clabel spacing

I have trouble with matplotlib / pyplot / basemap. I plot contour lines (air pressure) on a map. I use clabel to show the value of the contour lines. But the problem is: the padding between the value a…

Class-based view has no attribute .as_view() error

Im following this tutorial, trying to make an API for my Products table.Heres my .views/API/apitest.py view:from my_app.views.API.serializers import ProductSerializer from my_app.models import Product …