-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Debug custom Pylint check tests
When trying to debug the tests for a custom Pylint checker, remember that the tests are just like any other backend test. You may find our guide to debugging backend tests useful. That said, there are some helpful tips for working with Pylint checkers in particular. We describe them below.
Debugging a Pylint checker's tests often comes down to debugging the checker itself. To see how your checker behaves on some code, put that code into test.py
. Then assuming that your checker has message with symbol my-checker-message
, you can run your checker on test.py
like this:
$ PYTHONPATH=scripts/linters ../oppia_tools/pylint-2.8.3/bin/pylint --load-plugins=pylint_extensions --disable=all --enable=my-checker-message test.py
--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
(These instructions come from the Pylint documentation.) Note that the Pylint version number (2.8.3 in this case) may vary.
In this case, the checker found no issues with our code in test.py
, but your checker might flag problems with the code in test.py
. In either case, you should consider whether your checker behaved as expected. Did the checker flag any code that isn't actually a problem? Did the checker miss any problematic code? If the checker behaved unexpectedly, you should debug further. You may find two other debugging strategies useful: print statements and the Python debugger.
You can print out debugging information from your checker code using print()
statements. The output will appear when you run the checker as shown above. For example, if we added a print('DEBUGGING')
statement to our checker, we might see:
$ PYTHONPATH=scripts/linters ../oppia_tools/pylint-2.8.3/bin/pylint --load-plugins=pylint_extensions --disable=all --enable=my-checker-message test.py
DEBUGGING
--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
Just like when debugging backend tests, you can use the Python debugger, pdb, with Pylint checkers. You just need to add this code to your checker:
import pdb; pdb.set_trace()
If you aren't familiar with pdb, take a look at our guide to debugging backend tests.
Have an idea for how to improve the wiki? Please help make our documentation better by following our instructions for contributing to the wiki.
Core documentation
Developing Oppia
- FAQs
- How to get help
- Getting started with the project
- How the codebase is organized
- Making your first PR
- Debugging
- Testing
- Codebase policies and processes
- Guidelines for launching new features
- Guidelines for making an urgent fix (hotfix)
- Testing jobs and other features on production
- Guidelines for Developers with Write Access to oppia/oppia
- Release schedule and other information
- Revert and Regression Policy
- Privacy aware programming
- Code review:
- Project organization:
- QA Testing:
- Design docs:
- Team-Specific Guides
- LaCE/CD:
- Developer Workflow:
Developer Reference
- Oppiabot
- Git cheat sheet
- Frontend
- Backend
- Backend Type Annotations
- Writing state migrations
- Calculating statistics
- Storage models
- Coding for speed in GAE
- Adding a new page
- Adding static assets
- Wipeout Implementation
- Notes on NDB Datastore transactions
- How to handle merging of change lists for exploration properties
- Instructions for editing roles or actions
- Protocol buffers
- Webpack
- Third-party libraries
- Extension frameworks
- Oppia-ml Extension
- Mobile development
- Performance testing
- Build process
- Best practices for leading Oppia teams
- Past Events