Python模拟-如何模拟正则表达式

时间:2018-11-07 00:59:18

标签: python mocking pytest

有人知道如何模拟正则表达式吗?或者如何使以下代码起作用:

a.py

import re

def get_number_from_string():
    string = '3 monkies, 6 apes'
    string_split = string.split(',')

    fetch_number = re.match('[0-9]+', string_split[0])
    number = fetch_number.group(0)

    return number

test_a.py

import pytest
import a

def test_get_number_from_string():

    #with patch(somehow patch the re expression parts to return the int 10):

        number = a.get_number_from_string()

     assert number == 10

0 个答案:

没有答案