Finding unused Django code to remove

大憨熊 提交于 2019-11-29 00:05:44

问题


I've started working on a project with loads of unused legacy code in it. I was wondering if it might be possible to use a tool like coverage in combination with a crawler (like the django-test-utils one) to help me locate code which isn't getting hit which we can mark with deprecation warnings. I realise that something like this won't be foolproof but thought it might help.

I've tried running coverage.py with the django debug server but it doesn't work correctly (it seems to just profile the runserver machinery rather than my views, etc).

We're improving our test coverage all the time but there's a way to go and I thought there might be a quicker way.

Any thoughts?

Thanks.


回答1:


You can run the development server under coverage if you use the --noreload switch:

coverage run ./manage.py runserver --noreload



回答2:


pylint is great tool for static code analysis (among others things it will detect unused imports, variables or arguments).

  • http://nedbatchelder.com/blog/200806/pylint.html
  • http://www.doughellmann.com/articles/pythonmagazine/completely-different/2008-03-linters/index.html


来源:https://stackoverflow.com/questions/7050380/finding-unused-django-code-to-remove

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!