Python में Testing का परिचय
Alexander Levin
Data Scientist
autouse=True हो, तो fixture फ़ंक्शन बिना अनुरोध के भी चलता हैजब हमें कुछ environment तैयारियाँ या बदलाव सभी tests पर लागू करने हों।
उदाहरण, जब हम यह सुनिश्चित करना चाहें कि सभी tests:
ऐसे सभी मामलों में "autouse" argument उपयोग करें।
एक "autoused" fixture का उदाहरण:
import pytest
import pandas as pd
# Autoused fixture
@pytest.fixture(autouse=True)
def set_pd_options():
pd.set_option('display.max_columns', 5000)
# Test function
def test_pd_options():
assert pd.get_option('display.max_columns') == 5000
गलत "autoused" fixture का उदाहरण:
import pytest
import pandas as pd
# Wrong autoused fixture
@pytest.fixture(autouse=True)
def wrong_fixture():
return [1,2,3,4,5]
# Test function
def test_type():
assert type(wrong_fixture) == list
सुधारा हुआ fixture उदाहरण:
import pytest
import pandas as pd
# Wrong autoused fixture
@pytest.fixture
def correct_fixture():
return [1,2,3,4,5]
# Test function
def test_type(correct_fixture):
assert type(correct_fixture) == list
उदाहरण का आउटपुट:

autouse की परिभाषा: किसी fixture डेकोरेटर का वैकल्पिक boolean argument@pytest.fixture(autouse=True)autouse=True पर fixture फ़ंक्शन अनुरोध के बिना भी चलता हैPython में Testing का परिचय