I want to load the pytest fixture as a library somewhere else (pytest may not exist in the environment)

Even if you call the fixture as a normal function, ignoring the pytest decorator, it works fine if the signatures match.

However, if pytest itself does not exist, a detour is needed. For example, you can do the following:

try:
    import pytest
except ImportError:
    # provide fake pytest function to keep the script still runnable as standalone script
    def null_decorator_or_decomaker(f=None, **decomaker_kwargs):
        if f:
            # decorator
            return lambda *args, **kwargs: f(*args, **kwargs)
        else:
            # decomaker
            def _(f):
                # decomaker_kwargs can be handled
                return lambda *args, **kwargs: f(*args, **kwargs)
            return _
    def null_decomaker(*decomaker_args, **decomaker_kwargs):
        def _(f):
            return lambda *args, **kwargs: f(*args, **kwargs)
        return _
    def null_decorator(f):
        return lambda *args, **kwargs: f(*args, **kwargs)
    class pytest:
        fixture = staticmethod(null_decorator_or_decomaker)
        class mark:
            parametrize = staticmethod(null_decomaker)
        # other function declarations follow if required.

\ # I'm wondering if it's related to pytest anymore, but do you want to tag it? ..

Recommended Posts

I want to load the pytest fixture as a library somewhere else (pytest may not exist in the environment)
LINEbot development, I want to check the operation in the local environment
I want to print in a comprehension
I want to build a Python environment
I want to sort a list in the order of other lists
I want to save the trouble of inputting when debugging Paiza's skill check example in a local environment such as Jupyter [Python]
I want to use Python in the environment of pyenv + pipenv on Windows 10
[Words spelled to me when I was in the first grade ①] I'm not afraid to build a programming environment.
I want to create a window in Python
I want to set a life cycle in the task definition of ECS
I want to see a list of WebDAV files in the Requests module
I want to display the progress in Python!
Note that I was addicted to npm script not passing in the verification environment
I want to save a file with "Do not compress images in file" set in OpenPyXL
I want to embed a variable in a Python string
I want to transition with a button in flask
I want to write in Python! (2) Let's write a test
I want to randomly sample a file in Python
I want to easily build a model-based development environment
I want to work with a robot in python.
I want to write in Python! (3) Utilize the mock
I want to use the R dataset in python
I want to see the graph in 3D! I can make such a dream come true.
The story I was addicted to when I specified nil as a function argument in Go
A memorandum to register the library written in Hy in PyPI
I tried the super-resolution algorithm "PULSE" in a Windows environment
I want to start a jupyter environment with one command
A note on how to load a virtual environment in PyCharm
I want to use a virtual environment with jupyter notebook!
I want to make the Dictionary type in the List unique
I want to align the significant figures in the Numpy array
I want to make input () a nice complement in python
I want to create a Dockerfile for the time being.
I didn't want to write the AWS key in the program
When generating a large number of graphs with matplotlib, I do not want to display the graph on the screen (jupyter environment)
I want to create a graph with wavy lines omitted in the middle with matplotlib (I want to manipulate the impression)
I want to record the execution time and keep a log.
[Linux] I want to know the date when the user logged in
I created a Python library to call the LINE WORKS API
I wrote a function to load a Git extension script in Python
I want to create a system to prevent forgetting to tighten the key 1
I want to create a pipfile and reflect it in docker
I want to make the second line the column name in pandas
I want to pass the G test in one month Day 1
I want to know the population of each country in the world.
I made a command to display a colorful calendar in the terminal
Attempt to extend a function in the library (add copy function to pathlib)
I want to be healed by Mia Nanasawa's image. In such a case, hit the Twitter API ♪
I want to use complicated four arithmetic operations in the IF statement of the Django template! → Use a custom template
I want to use Ubuntu's desktop environment on Android for the time being (Termux version-Japanese input in desktop environment)
If you want a singleton in python, think of the module as a singleton
I want to separate the processing between test time and production environment
I want to send a signal only from the sub thread to the main thread
(Matplotlib) I want to draw a graph with a size specified in pixels
[C language] I want to generate random numbers in the specified range
How to install python package in local environment as a general user
I want to convert a table converted to PDF in Python back to CSV
I want to batch convert the result of "string" .split () in Python
I want to explain the abstract class (ABCmeta) of Python in detail.
I want to use the Django Debug Toolbar in my Ajax application
Environment maintenance made with Docker (I want to post-process GrADS in Python