728x90

assert 3

Assertion

메서드내용버전assertEqual(a, b)a == b assertNotEqual(a, b)a != b assertTrue(x)bool(x) is True assertFalse(x)bool(x) is False assertIs(a, b)a is b3.1assertIsNot(a, b)a is not b3.1assertIsNone(x)x is None3.1assertIsNotNone(x)x is not None3.1assertIn(a, b)a in b3.1assertNotIn(a, b)a not in b3.1assertIsInstance(a, b)isinstance(a, b)3.2assertNotIsInstance(a, b)not isinstance(a, b)3.2 docs.python.org에 있는 내용인..

Assertion

https://docs.pytest.org/en/stable/how-to/assert.html pytest 를 사용하면 표준 Python assert에 따라 값을 검증 할 수 있다고 한다.# content of test_assert1.pydef f(): return 3def test_function(): assert f() == 4 기본적인 assert 문은 조건이 참인지 확인하는데, 조건이 거짓이면 실패 메시지를 생성하고 테스트를 실패로 처리함.또한 아래 처럼 , 를 통해 사용자 메시지를 지정할 수도 있음def test_custom_message(): assert 1 + 1 == 3, "Expected 3" # 실패 시 사용자 메세지 출력 리스트에 2가 있는지 확인def test_co..

Programming/Pytest 2024.07.13

Chai - should, expect, assert

예제 함수로 공백을 제거하는 게 있다고 치자!function removeSpaces(str) { return str.replace(/\s+/g, '');} assert assert 는 Node.js의 기본 assert 모듈과 유사한 방법으로 작동으로 함수의 인자에 기대값과 실제값을 전달import * as chai from 'chai';import { removeSpaces } from '../index.js';const { assert } = chai;describe('removeSpaces with Assert', () => { it('가운데 공백 제거', () => { const input = 'Hello World'; const expectedOutput = 'He..

728x90