Closed as not planned
Description
Overview of issue
I am having an issue with BeautifulSoup and pytest. When I run pytest I get the following error:
TypeError: object.new() takes exactly one argument (the type to instantiate)
at this line of code in the function being tested:
soup = BeautifulSoup(response.text, 'html.parser')
I have no idea why this is happening but it means that I can't perform testing where BeautifulSoup is present. If I mock it I still run into the error, the only way to suppress it is to mock the new function, but this then leads to a whole host of other issues.
Here is the test code that fails:
def test_some_function(mocker):
mocker.patch('requests.get')
response_mock = mocker.Mock()
response_mock.text = 'some text'
requests.get.return_value = response_mock
_some_function('https://example.com')
requests.get.assert_called_once_with(
url='https://example.com', headers=headers)
Pip List output
annotated-types 0.6.0
anyio 4.3.0
asttokens 2.4.1
beautifulsoup4 4.12.3
blessed 1.20.0
botocore 1.34.75
bs4 0.0.2
certifi 2024.2.2
chalice 1.31.0
charset-normalizer 3.3.2
click 8.1.7
decorator 5.1.1
distro 1.9.0
executing 2.1.0
h11 0.14.0
httpcore 1.0.5
httpx 0.27.0
idna 3.6
iniconfig 2.0.0
inquirer 2.10.1
ipython 8.27.0
jedi 0.19.1
jmespath 1.0.1
matplotlib-inline 0.1.7
openai 1.16.1
packaging 24.0
parso 0.8.4
pexpect 4.9.0
pinecone-client 3.2.2
pip 23.3.2
pluggy 1.4.0
prompt_toolkit 3.0.47
ptyprocess 0.7.0
pure_eval 0.2.3
pydantic 2.6.4
pydantic_core 2.16.3
Pygments 2.18.0
pytest 8.1.1
pytest-mock 3.14.0
python-dateutil 2.9.0.post0
python-dotenv 1.0.1
python-editor 1.0.4
PyYAML 6.0.1
readchar 4.0.6
requests 2.31.0
setuptools 69.2.0
six 1.16.0
sniffio 1.3.1
soupsieve 2.5
stack-data 0.6.3
tqdm 4.66.2
traitlets 5.14.3
typing_extensions 4.10.0
urllib3 2.2.1
wcwidth 0.2.13
wheel 0.43.0
Pytest version & OS Version
Pytest 8.1.1
mac sonoma 14.6.1