5353 ELASTICSEARCH_URL = "http://localhost:9200"
5454
5555
56- def get_test_client (wait : bool = True , ** kwargs : Any ) -> Elasticsearch :
56+ def get_test_client (url , wait : bool = True , ** kwargs : Any ) -> Elasticsearch :
5757 # construct kwargs from the environment
5858 kw : Dict [str , Any ] = {"request_timeout" : 30 }
5959
6060 if "PYTHON_CONNECTION_CLASS" in os .environ :
6161 kw ["node_class" ] = os .environ ["PYTHON_CONNECTION_CLASS" ]
6262
6363 kw .update (kwargs )
64- client = Elasticsearch (ELASTICSEARCH_URL , ** kw )
64+ client = Elasticsearch (url , ** kw )
6565
6666 # wait for yellow status
6767 for tries_left in range (100 if wait else 1 , 0 , - 1 ):
@@ -76,15 +76,15 @@ def get_test_client(wait: bool = True, **kwargs: Any) -> Elasticsearch:
7676 raise SkipTest ("Elasticsearch failed to start." )
7777
7878
79- async def get_async_test_client (wait : bool = True , ** kwargs : Any ) -> AsyncElasticsearch :
79+ async def get_async_test_client (url , wait : bool = True , ** kwargs : Any ) -> AsyncElasticsearch :
8080 # construct kwargs from the environment
8181 kw : Dict [str , Any ] = {"request_timeout" : 30 }
8282
8383 if "PYTHON_CONNECTION_CLASS" in os .environ :
8484 kw ["node_class" ] = os .environ ["PYTHON_CONNECTION_CLASS" ]
8585
8686 kw .update (kwargs )
87- client = AsyncElasticsearch (ELASTICSEARCH_URL , ** kw )
87+ client = AsyncElasticsearch (url , ** kw )
8888
8989 # wait for yellow status
9090 for tries_left in range (100 if wait else 1 , 0 , - 1 ):
@@ -100,36 +100,6 @@ async def get_async_test_client(wait: bool = True, **kwargs: Any) -> AsyncElasti
100100 raise SkipTest ("Elasticsearch failed to start." )
101101
102102
103- class ElasticsearchTestCase (TestCase ):
104- client : Elasticsearch
105-
106- @staticmethod
107- def _get_client () -> Elasticsearch :
108- return get_test_client ()
109-
110- @classmethod
111- def setup_class (cls ) -> None :
112- cls .client = cls ._get_client ()
113-
114- def teardown_method (self , _ : Any ) -> None :
115- # Hidden indices expanded in wildcards in ES 7.7
116- expand_wildcards = ["open" , "closed" ]
117- if self .es_version () >= (7 , 7 ):
118- expand_wildcards .append ("hidden" )
119-
120- self .client .indices .delete_data_stream (
121- name = "*" , expand_wildcards = expand_wildcards
122- )
123- self .client .indices .delete (index = "*" , expand_wildcards = expand_wildcards )
124- self .client .indices .delete_template (name = "*" )
125- self .client .indices .delete_index_template (name = "*" )
126-
127- def es_version (self ) -> Tuple [int , ...]:
128- if not hasattr (self , "_es_version" ):
129- self ._es_version = _get_version (self .client .info ()["version" ]["number" ])
130- return self ._es_version
131-
132-
133103def _get_version (version_string : str ) -> Tuple [int , ...]:
134104 if "." not in version_string :
135105 return ()
@@ -138,19 +108,19 @@ def _get_version(version_string: str) -> Tuple[int, ...]:
138108
139109
140110@fixture (scope = "session" )
141- def client () -> Elasticsearch :
111+ def client (elasticsearch_url ) -> Elasticsearch :
142112 try :
143- connection = get_test_client (wait = "WAIT_FOR_ES" in os .environ )
113+ connection = get_test_client (elasticsearc_url , wait = "WAIT_FOR_ES" in os .environ )
144114 add_connection ("default" , connection )
145115 return connection
146116 except SkipTest :
147117 skip ()
148118
149119
150120@pytest_asyncio .fixture
151- async def async_client () -> AsyncGenerator [AsyncElasticsearch , None ]:
121+ async def async_client (elasticsearch_url ) -> AsyncGenerator [AsyncElasticsearch , None ]:
152122 try :
153- connection = await get_async_test_client (wait = "WAIT_FOR_ES" in os .environ )
123+ connection = await get_async_test_client (elasticsearch_url , wait = "WAIT_FOR_ES" in os .environ )
154124 add_async_connection ("default" , connection )
155125 yield connection
156126 await connection .close ()
0 commit comments