Setting to debug test by entering the contents of the library with pytest

Synopsis

When doing tests such as pytest and unittest, stepping through your own code may not solve the problem. In such a case, you may want to debug even the installed library. You can also set breakpoints in libraries installed with pip etc. by making the following settings.

However, the library implemented in C language requires a method like the reference page introduced at the end of this article.

For normal debugging

During normal debugging, not debug testing Please see Settings to debug the contents of the library with VS Code.

Usual settings

Normally, when debugging with vscode, I think that launch.json often has the following settings.

launch.json


{
    //You can use IntelliSense to learn the available attributes.
    //Hover and display the description of existing attributes.
    //Check the following for more information: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }
    ]
}

Settings to dive into other people's libraries in debug tests

If there is a configuration where "request" is "test", it will be used during debug testing.

Also, only the first one of this configuration will be loaded. Subsequent similar configurations will be ignored.

There is justMyCode in this configuration, and you can switch between" ** only your own code ** ".

launch.json


{
    //You can use IntelliSense to learn the available attributes.
    //Hover and display the description of existing attributes.
    //Check the following for more information: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        },
        {
            "name": "Debug Tests",
            "type": "python",
            "request": "test",
            "console": "integratedTerminal",
            "justMyCode": false
        }
    ]
}

For libraries implemented in C language

The mixed mode debugging function is called [Debugging Python and C ++ at the same time](https://docs.microsoft.com/en-us/visualstudio/python/debugging-mixed-mode-c-cpp-python-in- visual-studio? view = vs-2019) The method is provided in Visual Studio. Even with VScode, you can debug various libraries by referring to How to debug (step) mixed Python and OpenCV.

Excelsior!

Recommended Posts

Setting to debug test by entering the contents of the library with pytest
Settings to debug the contents of the library with VS Code
Try to get the contents of Word with Golang
How to test the attributes added by add_request_method of pyramid
Debug by attaching to the Python process of the SSH destination
Output the contents of ~ .xlsx in the folder to HTML with Python
[Introduction to Python] How to sort the contents of a list efficiently with list sort
I tried to verify the result of A / B test by chi-square test
Feel free to write a test with nose (in the case of + gevent)
Setting to output the log of cron execution
Dump the contents of redis db with lua
How to test the current time with Go (I made a very thin library)
Template of python script to read the contents of the file
Add information to the bottom of the figure with Matplotlib
Example of pytest environment to fix database with Docker
[Introduction to Python] Basic usage of the library matplotlib
How to check if the contents of the dictionary are the same in Python by hash value
Let's introduce the library currently used by engineers with about 3 years of experience in Django
Create a 2D array by adding a row to the end of an empty array with numpy
Try to import to the database by manipulating ShapeFile of national land numerical information with Python
How to plot a lot of legends by changing the color of the graph continuously with matplotlib
I tried to predict the sales of game software with VARISTA by referring to the article of Codexa
I tried to find the entropy of the image with python
Switch the setting value of setting.py according to the development environment
[Ubuntu] How to delete the entire contents of a directory
I tried to find the average of the sequence with TensorFlow
How to debug the Python standard library in Visual Studio
Inherit the standard library to find the average value of Queue
Run the intellisense of your own python library with VScode.
Try to automate the operation of network devices with Python
How to see the contents of the Jupyter notebook ipynb file
Get the source of the page to load infinitely with python.
Apply monkey patch to all methods of pytest test class
How to connect the contents of a list into a string
Try to extract the features of the sensor data with CNN
I tried to verify the speaker identification by the Speaker Recognition API of Azure Cognitive Services with Python. # 1
I tried to verify the speaker identification by the Speaker Recognition API of Azure Cognitive Services with Python. # 2
Find the white Christmas rate by prefecture with Python and map it to a map of Japan
I tried to summarize the contents of each package saved by Python pip in one line
How to intercept or tamper with the SSL communication of the actual iOS device by a proxy
Unit test flask with pytest
Test standard output with Pytest
Simulation of the contents of the wallet
Process the contents of the file in order with a shell script
A story stuck with the installation of the machine learning library JAX
The story of not being able to run pygame with pycharm
Save the results of crawling with Scrapy to the Google Data Store
Become familiar with (want to be) around the pipeline of spaCy
I tried to automate the watering of the planter with Raspberry Pi
[python, ruby] fetch the contents of a web page with selenium-webdriver
How to get the ID of Type2Tag NXP NTAG213 with nfcpy
[EC2] How to install chrome and the contents of each command
[Introduction to StyleGAN] I played with "The Life of a Man" ♬
Try to solve the N Queens problem with SA of PyQUBO
Read all the contents of proc / [pid] ~ From setgroups to wchan ~
I want to output the beginning of the next month with Python
Consider the speed of processing to shift the image buffer with numpy.ndarray
Can I pass the first grade of math test by programming?
Solving the Maze with Python-Supplement to Chapter 6 of the Algorithm Quick Reference-
Read all the contents of proc / [pid] ~ From cwd to loginuid ~
[TensorFlow 2] How to check the contents of Tensor in graph mode