A pytest plugin that enables you to test your code that relies on a running Elasticsearch search engine

Overview

https://raw.githubusercontent.com/ClearcodeHQ/pytest-elasticsearch/master/logo.png

pytest-elasticsearch

Latest PyPI version Wheel Status Supported Python Versions License

What is this?

This is a pytest plugin that enables you to test your code that relies on a running Elasticsearch search engine. It allows you to specify fixtures for Elasticsearch process and client.

How to use

Warning

This plugin requires at least version 5.0 of elasticsearch to work.

The plugin contains two fixtures:

  • elasticsearch - a client fixture that has functional scope, and which cleans Elasticsearch at the end of each test.
  • elasticsearch_proc - a session scoped fixture, that starts Elasticsearch instance at its first use and stops at the end of the tests.
  • elasticsearch_nooproc - a nooprocess fixture, that's holds connection data to already running elasticsearch

Simply include one of these fixtures into your tests fixture list.

You can also create additional elasticsearch client and process fixtures if you'd need to:

from pytest_elasticsearch import factories

elasticsearch_my_proc = factories.elasticsearch_proc(
    port=None, logsdir='/tmp')
elasticsearch_my = factories.elasticsearch('elasticsearch_my_proc')

Note

Each elasticsearch process fixture can be configured in a different way than the others through the fixture factory arguments.

Connecting to already existing Elasticsearch service

Some projects are using already running Elasticsearch servers (ie on docker instances). In order to connect to them, one would be using the elasticsearch_nooproc fixture.

es_external = factories.elasticsearch('elasticsearch_nooproc')

By default the elasticsearch_nooproc fixture would connect to elasticsearch instance using 9300 port.

Configuration

You can define your settings in three ways, it's fixture factory argument, command line option and pytest.ini configuration option. You can pick which you prefer, but remember that these settings are handled in the following order:

  1. Fixture factory argument
  2. Command line option
  3. Configuration option in your pytest.ini file
Configuration options
ElasticSearch option Fixture factory argument Command line option pytest.ini option Noop process fixture Default
Elasticsearch executable executable --elasticsearch-executable elasticsearch_executable   /usr/share/elasticsearch/bin/elasticsearch
logs directory logsdir --elasticsearch-logsdir elasticsearch_logsdir
$TMPDIR
host host --elasticsearch-host elasticsearch_host host 127.0.0.1
port port -elasticsearch-port elasticsearch_port 6300 random
Elasticsearch cluster name cluster_name --elasticsearch-cluster-name elasticsearch_cluster_name
elasticsearch_cluster_
index storage type index_store_type --elasticsearch-index-store-type elasticsearch_index_store_type
mmapfs
network publish host network_publish_host --elasticsearch-network-publish-host elasticsearch_network_publish_host
127.0.0.1
logs prefix logs_prefix --elasticsearch-logs-prefix elasticsearch_logs_prefix
 
transport tcp port transport_tcp_port --elasticsearch-transport-tcp-port elasticsearch_transport_tcp_port
random

Example usage:

  • pass it as an argument in your own fixture

    elasticsearch_proc = factories.elasticsearch_proc(
        cluster_name='awsome_cluster)
  • use --elasticsearch-logsdir command line option when you run your tests

    py.test tests --elasticsearch-cluster-name=awsome_cluster
    
  • specify your directory as elasticsearch_cluster_name in your pytest.ini file.

    To do so, put a line like the following under the [pytest] section of your pytest.ini:

    [pytest]
    elasticsearch_cluster_name = awsome_cluster

Known issues

It might happen, that the process can't be started due to lack of permissions. The files that user running tests has to have access to are:

  • /etc/default/elasticsearch

Make sure that you either run tests as a user that has access to these files, or you give user proper permissions or add it to proper user groups.

In CI at the moment, we install elasticsearch from tar/zip archives, which do not set up additional permission restrictions, so it's not a problem on the CI/CD.

Package resources

Owner
Clearcode
Software house with a passion for technology. We specialize in building enterprise-grade adtech, martech and analytics platforms.
Clearcode
Avocado is a set of tools and libraries to help with automated testing.

Welcome to Avocado Avocado is a set of tools and libraries to help with automated testing. One can call it a test framework with benefits. Native test

Ana Guerrero Lopez 1 Nov 19, 2021
catsim - Computerized Adaptive Testing Simulator

catsim - Computerized Adaptive Testing Simulator Quick start catsim is a computerized adaptive testing simulator written in Python 3.4 (with modificat

Nguyễn Văn Anh Tuấn 1 Nov 29, 2021
Python wrapper of Android uiautomator test tool.

uiautomator This module is a Python wrapper of Android uiautomator testing framework. It works on Android 4.1+ (API Level 16~30) simply with Android d

xiaocong 1.9k Dec 30, 2022
Android automation project with pytest+appium

Android automation project with pytest+appium

1 Oct 28, 2021
Testing Calculations in Python, using OOP (Object-Oriented Programming)

Testing Calculations in Python, using OOP (Object-Oriented Programming) Create environment with venv python3 -m venv venv Activate environment . venv

William Koller 1 Nov 11, 2021
自动化爬取并自动测试所有swagger-ui.html显示的接口

swagger-hack 在测试中偶尔会碰到swagger泄露 常见的泄露如图: 有的泄露接口特别多,每一个都手动去试根本试不过来 于是用python写了个脚本自动爬取所有接口,配置好传参发包访问 原理是首先抓取http://url/swagger-resources 获取到有哪些标准及对应的文档地

jayus 534 Dec 29, 2022
CNE-OVS-SIT - OVS System Integration Test Suite

CNE-OVS-SIT - OVS System Integration Test Suite Introduction User guide Discussion Introduction CNE-OVS-SIT is a test suite for OVS end-to-end functio

4 Jan 09, 2022
Travel through time in your tests.

time-machine Travel through time in your tests. A quick example: import datetime as dt

Adam Johnson 373 Dec 27, 2022
Network automation lab using nornir, scrapli, and containerlab with Arista EOS

nornir-scrapli-eos-lab Network automation lab using nornir, scrapli, and containerlab with Arista EOS. Objectives Deploy base configs to 4xArista devi

Vireak Ouk 13 Jul 07, 2022
The evaluator covering all of the metrics required by tasks within the DUE Benchmark.

DUE Evaluator The repository contains the evaluator covering all of the metrics required by tasks within the DUE Benchmark, i.e., set-based F1 (for KI

DUE Benchmark 4 Jan 21, 2022
An interactive TLS-capable intercepting HTTP proxy for penetration testers and software developers.

mitmproxy mitmproxy is an interactive, SSL/TLS-capable intercepting proxy with a console interface for HTTP/1, HTTP/2, and WebSockets. mitmdump is the

mitmproxy 29.7k Jan 02, 2023
UUM Merit Form Filler is a web automation which helps automate entering a matric number to the UUM system in order for participants to obtain a merit

About UUM Merit Form Filler UUM Merit Form Filler is a web automation which helps automate entering a matric number to the UUM system in order for par

Ilham Rachmat 3 May 31, 2022
Python program that uses pynput to simulate key presses. Probably only works on Windows.

AutoKey Python program that uses pynput to simulate key presses. Probably only works on Windows. Can be used for pretty much whatever you want except

2 Oct 28, 2022
A configurable set of panels that display various debug information about the current request/response.

Django Debug Toolbar The Django Debug Toolbar is a configurable set of panels that display various debug information about the current request/respons

Jazzband 7.3k Jan 02, 2023
Webscreener is a tool for mass web domains pentesting.

Webscreener is a tool for mass web domains pentesting. It is used to take snapshots for domains that is generated by a tool like knockpy or Sublist3r. It cuts out most of the pentesting time by scree

Seekurity 3 Jun 07, 2021
Docker-based integration tests

Docker-based integration tests Description Simple pytest fixtures that help you write integration tests with Docker and docker-compose. Specify all ne

Avast 326 Dec 27, 2022
Wraps any WSGI application and makes it easy to send test requests to that application, without starting up an HTTP server.

WebTest This wraps any WSGI application and makes it easy to send test requests to that application, without starting up an HTTP server. This provides

Pylons Project 325 Dec 30, 2022
🐍 Material for PyData Global 2021 Presentation: Effective Testing for Machine Learning Projects

Effective Testing for Machine Learning Projects Code for PyData Global 2021 Presentation by @edublancas. Slides available here. The project is develop

Eduardo Blancas 73 Nov 06, 2022
reCaptchaBypasser For Bypass Any reCaptcha For Selenium Python

reCaptchaBypasser ' Usage : from selenium import webdriver from reCaptchaBypasser import reCaptchaScraper import time driver = webdriver.chrome(execu

Dr.Linux 8 Dec 17, 2022
A modern API testing tool for web applications built with Open API and GraphQL specifications.

Schemathesis Schemathesis is a modern API testing tool for web applications built with Open API and GraphQL specifications. It reads the application s

Schemathesis.io 1.6k Dec 30, 2022