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
A simple serverless create api test repository. Please Ignore.

serverless-create-api-test A simple serverless create api test repository. Please Ignore. Things to remember: Setup workflow Change Name in workflow e

Sarvesh Bhatnagar 1 Jan 18, 2022
Main purpose of this project is to provide the service to automate the API testing process

PPTester project Main purpose of this project is to provide the service to automate the API testing process. In order to deploy this service use you s

4 Dec 16, 2021
Django test runner using nose

django-nose django-nose provides all the goodness of nose in your Django tests, like: Testing just your apps by default, not all the standard ones tha

Jazzband 880 Dec 15, 2022
Minimal example of getting Django + PyTest running on GitHub Actions

Minimal Django + Pytest + GitHub Actions example This minimal example shows you how you can runs pytest on your Django app on every commit using GitHu

Matt Segal 5 Sep 19, 2022
输入Google Hacking语句,自动调用Chrome浏览器爬取结果

Google-Hacking-Crawler 该脚本可输入Google Hacking语句,自动调用Chrome浏览器爬取结果 环境配置 python -m pip install -r requirements.txt 下载Chrome浏览器

Jarcis 4 Jun 21, 2022
Front End Test Automation with Pytest Framework

Front End Test Automation Framework with Pytest Installation and running instructions: 1. To install the framework on your local machine: clone the re

Sergey Kolokolov 2 Jun 17, 2022
Python drivers for YeeNet firmware

yeenet-router-driver-python Python drivers for YeeNet firmware This repo is under heavy development. Many or all of these scripts are not likely to wo

Jason Paximadas 1 Dec 26, 2021
Python scripts for a generic performance testing infrastructure using Locust.

TODOs Reference to published paper or online version of it loadtest_plotter.py: Cleanup and reading data from files ARS_simulation.py: Cleanup, docume

Juri Tomak 3 Dec 15, 2022
HTTP load generator, ApacheBench (ab) replacement, formerly known as rakyll/boom

hey is a tiny program that sends some load to a web application. hey was originally called boom and was influenced from Tarek Ziade's tool at tarekzia

Jaana Dogan 14.9k Jan 07, 2023
Flexible test automation for Python

Nox - Flexible test automation for Python nox is a command-line tool that automates testing in multiple Python environments, similar to tox. Unlike to

Stargirl Flowers 941 Jan 03, 2023
The (Python-based) mining software required for the Game Boy mining project.

ntgbtminer - Game Boy edition This is a version of ntgbtminer that works with the Game Boy bitcoin miner. ntgbtminer ntgbtminer is a no thrills getblo

Ghidra Ninja 31 Nov 04, 2022
Selenium Page Object Model with Python

Page-object-model (POM) is a pattern that you can apply it to develop efficient automation framework.

Mohammad Ifran Uddin 1 Nov 29, 2021
Fail tests that take too long to run

GitHub | PyPI | Issues pytest-fail-slow is a pytest plugin for making tests fail that take too long to run. It adds a --fail-slow DURATION command-lin

John T. Wodder II 4 Nov 27, 2022
Enabling easy statistical significance testing for deep neural networks.

deep-significance: Easy and Better Significance Testing for Deep Neural Networks Contents ⁉️ Why 📥 Installation 🔖 Examples Intermezzo: Almost Stocha

Dennis Ulmer 270 Dec 20, 2022
A simple asynchronous TCP/IP Connect Port Scanner in Python 3

Python 3 Asynchronous TCP/IP Connect Port Scanner A simple pure-Python TCP Connect port scanner. This application leverages the use of Python's Standa

70 Jan 03, 2023
This repository contains a testing script for nmigen-boards that tries to build blinky for all the platforms provided by nmigen-boards.

Introduction This repository contains a testing script for nmigen-boards that tries to build blinky for all the platforms provided by nmigen-boards.

S.J.R. van Schaik 4 Jul 23, 2022
🎓 Stepik Academy Автоматизация тестирования на Python

🎓 Stepik Academy Автоматизация тестирования на Python Запуск тестов выполняется в командной строке: pytest -v --tb=line --language=en --alluredir=all

Sergey 1 Dec 03, 2021
A folder automation made using Watch-dog, it only works in linux for now but I assume, it will be adaptable to mac and PC as well

folder-automation A folder automation made using Watch-dog, it only works in linux for now but I assume, it will be adaptable to mac and PC as well Th

Parag Jyoti Paul 31 May 28, 2021
WrightEagle AutoTest (Has been updated by Cyrus team members)

Autotest2d WrightEagle AutoTest (Has been updated by Cyrus team members) Thanks go to WrightEagle Members. Steps 1- prepare start_team file. In this s

Cyrus Soccer Simulation 2D Team 3 Sep 01, 2022