ã¯ããã« Django Restframework ã§éçºããAPIã«å¯¾ãããã¹ãã³ã¼ããä½æããã ãã®ããã«å¿ è¦ãªãã¦ãã¦ãããã±ã¼ã¸ãªã©ã«ã¤ãã¦ã¾ã¨ããã ãµã³ãã«ã³ã¼ã ãã¡ãã«ä½æããã³ã¼ããåèã«ä»¥ä¸ã®è©±ãé²ãã¦ããã sampleapp.tests é ä¸ã«ãã¹ãç¨ã®ã³ã¼ããä½æãã¦ããã 使ç¨ããã©ã¤ãã©ãªç Pythonã¯3.8.x Django 3.0.x Django Restframework 3.11.x factory-boy 2.11.x pytest 4.0.x pytest-django 3.4.x ãã¹ãåãã®ã©ã¤ãã©ãªèª¬æ factory-boy ãã¹ããã¼ã¿ãç°¡åã«ä½æããããã®ã©ã¤ãã©ãªã https://factoryboy.readthedocs.io/en/latest/ https://github.com/FactoryBoy/factor
pytestã§coverageã測ããããããããã°ãè²ã ã¹ãã¼ãã¢ããããäºæãããã ã¨ããããããã£ã¦ã¿ã話ã venvç°å¢ãä½ã pytestã§ãã¹ãã§ããããã«ãã pytest-covã使ã ã«ãã¬ãã¸ä¸ãã¦ã¿ã djangoã§pytestã§ã«ãã¬ãã¸ãå³ã djangoã®æºå pytestã§djangoããã¹ã pytest + django + coverage çµãã venvç°å¢ãä½ã $ python3.6 -m venv coverage $ . coverage/bin/activate (coverage) $ python -V Python 3.6.5 pytestã§ãã¹ãã§ããããã«ãã ã¨ãããããpytestã§ãã¹ãã§ããããã«ãã¨ãã (coverage) $ pip install pytest (coverage) $ pip freeze |
Djangoã®ãã¹ãã«ã¤ãã¦èãã¦ããã¨ããã以ä¸ã®è¨äºã«åºä¼ãã¾ããã Djangoã®ãã¹ãã®æ¸ãæ¹ã«ã¤ãã¦åå¼·ããã®ã§ã¾ã¨ãã - c-bata web Django Best Practice ã¸ã®é #2 å¾è ã®è¨äºã«ãããéããpytestã§ã¯ãã¹ãã®å¤±æå 容ãç´°ããåºãããã§ããã ãã®ãããDjangoåãã®pytestã©ã¤ãã©ãªpytest-djangoã使ã£ã¦ãã¹ãã³ã¼ããæ¸ãã¦ã¿ã¾ããã ç®æ¬¡ ç°å¢ 試ãããã©åãããªãã£ãã㨠試ãã¦ãªãã㨠ãã¹ã対象ã®ã¢ã㪠ã»ããã¢ããã¨ã¢ããªä½æ pytest.iniã®ä½æ Modelã®ãã¹ã URL解決ã®ãã¹ã Viewã®ãã¹ã Clientã使ãå ´å RequestFactoryã使ãå ´å Formã®ãã¹ã å ¨ä½ã®æµãã®ãã¹ã æ£å¸¸ç³» ãªãã¤ã¬ã¯ãã®ç¢ºèª ãã³ãã¬ã¼ãã«æ¸¡ãcontextã®å¤ã®ç¢ºèª Viewã®ç¢ºèª ãã¼ã¿ã
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}