[{"data":1,"prerenderedAt":214},["ShallowReactive",2],{"/open_source/contribution/writing_tests":3,"surround-/open_source/contribution/writing_tests":198},{"id":4,"title":5,"avatar":6,"banner":6,"body":7,"category":6,"desc":191,"description":53,"extension":192,"links":6,"meta":193,"navigation":6,"path":194,"seo":195,"stem":196,"__hash__":197},"docs/en/open_source/contribution/writing_tests.md","How to Write Unit Tests",null,{"type":8,"value":9,"toc":183},"minimark",[10,15,43,47,109,113,116,133,139,143,146,151,158,162,173,179],[11,12,14],"h2",{"id":13},"writing-a-test","Writing a Test",[16,17,18,31,36],"ol",{},[19,20,21,22,26,27,30],"li",{},"Create a new Python file in the ",[23,24,25],"code",{},"tests/"," directory. The filename should start with ",[23,28,29],{},"test_",".",[19,32,33,34,30],{},"Inside the file, create functions whose names start with ",[23,35,29],{},[19,37,38,39,42],{},"Use the ",[23,40,41],{},"assert"," statement to check for expected outcomes.",[44,45,46],"p",{},"Here is a basic example:",[48,49,54],"pre",{"className":50,"code":51,"language":52,"meta":53,"style":53},"language-python shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","# tests/test_example.py\n\ndef test_addition():\n    assert 1 + 1 == 2\n","python","",[23,55,56,65,72,87],{"__ignoreMap":53},[57,58,61],"span",{"class":59,"line":60},"line",1,[57,62,64],{"class":63},"sHwdD","# tests/test_example.py\n",[57,66,68],{"class":59,"line":67},2,[57,69,71],{"emptyLinePlaceholder":70},true,"\n",[57,73,75,79,83],{"class":59,"line":74},3,[57,76,78],{"class":77},"spNyl","def",[57,80,82],{"class":81},"s2Zo4"," test_addition",[57,84,86],{"class":85},"sMK4o","():\n",[57,88,90,94,98,101,103,106],{"class":59,"line":89},4,[57,91,93],{"class":92},"s7zQu","    assert",[57,95,97],{"class":96},"sbssI"," 1",[57,99,100],{"class":85}," +",[57,102,97],{"class":96},[57,104,105],{"class":85}," ==",[57,107,108],{"class":96}," 2\n",[11,110,112],{"id":111},"running-tests","Running Tests",[44,114,115],{},"To run all the tests, execute the following command from the root of the project:",[48,117,121],{"className":118,"code":119,"language":120,"meta":53,"style":53},"language-bash shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","make test\n","bash",[23,122,123],{"__ignoreMap":53},[57,124,125,129],{"class":59,"line":60},[57,126,128],{"class":127},"sBMFI","make",[57,130,132],{"class":131},"sfazB"," test\n",[44,134,135,136,138],{},"This will discover and run all the tests in the ",[23,137,25],{}," directory.",[11,140,142],{"id":141},"advanced-techniques","Advanced Techniques",[44,144,145],{},"Pytest has many advanced features, such as fixtures and mocking.",[147,148,150],"h3",{"id":149},"fixtures","Fixtures",[44,152,153,154,157],{},"Fixtures are functions that can provide data or set up state for your tests. They are defined using the ",[23,155,156],{},"@pytest.fixture"," decorator.",[147,159,161],{"id":160},"mocking","Mocking",[44,163,164,165,168,169,172],{},"Mocking is used to replace parts of your system with mock objects. This is useful for isolating the code you are testing. The ",[23,166,167],{},"unittest.mock"," library is commonly used for this, often with the ",[23,170,171],{},"patch"," function.",[44,174,175,176,30],{},"For an example of mocking, see ",[23,177,178],{},"tests/test_hello_world.py",[180,181,182],"style",{},"html pre.shiki code .sHwdD, html code.shiki .sHwdD{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic}html pre.shiki code .spNyl, html code.shiki .spNyl{--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA}html pre.shiki code .s2Zo4, html code.shiki .s2Zo4{--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF}html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .s7zQu, html code.shiki .s7zQu{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#89DDFF;--shiki-dark-font-style:italic}html pre.shiki code .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sBMFI, html code.shiki .sBMFI{--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}",{"title":53,"searchDepth":67,"depth":67,"links":184},[185,186,187],{"id":13,"depth":67,"text":14},{"id":111,"depth":67,"text":112},{"id":141,"depth":67,"text":142,"children":188},[189,190],{"id":149,"depth":74,"text":150},{"id":160,"depth":74,"text":161},"This project uses [pytest](https://docs.pytest.org/) for unit testing.","md",{},"/en/open_source/contribution/writing_tests",{"title":5,"description":53},"en/open_source/contribution/writing_tests","KD1NBuWtE1fP5u0WX_7Shsc8CdQVr0__-xQAI2E_STE",[199,207],{"title":200,"path":201,"stem":202,"icon":203,"framework":6,"module":6,"class":204,"target":-1,"active":205,"defaultOpen":205,"children":-1,"description":206},"Documentation Writing Guidelines","/open_source/contribution/writing_docs","open_source/contribution/writing_docs","i-ri-article-line",[],false,"This project uses Nuxt Content to build a documentation system that supports Markdown and rich Vue components.",{"title":208,"path":209,"stem":210,"icon":211,"framework":6,"module":6,"class":212,"target":213,"active":205,"defaultOpen":70,"children":-1,"description":-1},"API Reference","/api-reference/search-memories","api-reference/search-memories","i-ri-file-code-line",[],"_blank",1770372091168]