<aside>
</aside>
unittest.mock
์ Mock
ํด๋์ค ๋ฐ patch
๊ธฐ๋ฅ์ผ๋ก ์์กด์ฑ ๊ฐ์ง ๊ฐ์ฒด ๋์ฒด ๋ฐฉ๋ฒ ์ตํ๊ธฐpatch
๋ฐ์ฝ๋ ์ดํฐ ๋ฐ ์ปจํ
์คํธ ๋งค๋์ ์ฌ์ฉ๋ฒ ์ดํด ๋ฐ ์ ์ฉmonkeypatch
ํฝ์ค์ฒ๋ก ํ๊ฒฝ ๋ณ์/ํจ์ ๋ฑ ์์ ๋ณ๊ฒฝ ๋ฐฉ๋ฒ ์๊ธฐํ๋ก์ ํธ ๊ตฌ์กฐ:
graph TD
A(my-pytest-project) --> B(.venv);
A --> C(mycalc);
A --> D(tests);
A --> E(pytest.ini);
C --> C1(__init__.py);
C --> C2(calculator.py);
C --> C3(exchange.py ์ธ๋ถ ์์กด์ฑ ๋ชจ๋);
D --> D1(__init__.py);
D --> D2(test_calculator.py);
D --> D3(conftest.py);
D --> D4(test_scopes.py);
D --> D5(test_markers.py);
D --> D6(test_exchange.py Mock ํ
์คํธ ํ์ผ);
style B fill:#eee,stroke:#333,stroke-dasharray: 5 5;
style C fill:#ccf,stroke:#333;
style D fill:#cfc,stroke:#333;
style E fill:#fef,stroke:#333;
style C2 fill:#cce,stroke:#333;
style C3 fill:#fda,stroke:#333;
style D2 fill:#cef,stroke:#333;
style D3 fill:#fec,stroke:#333;
style D4 fill:#dff,stroke:#333;
style D5 fill:#ffd,stroke:#333;
style D6 fill:#adf,stroke:#333;
mycalc/exchange.py
(์ ์์ค ์ฝ๋ ํ์ผ - ์ธ๋ถ ์์กด์ฑ ํฌํจ):tests/test_exchange.py
(์ ํ
์คํธ ํ์ผ - Mock ๊ฐ์ฒด ํ์ฉ):