KKimj / PerformanceFuzzer

PerformanceFuzzer
https://pypi.org/project/PerformanceFuzzer/
GNU General Public License v3.0
2 stars 0 forks source link

pytest: error: unrecognized arguments: --benchmark-autosave #2

Closed KKimj closed 3 years ago

KKimj commented 3 years ago

image

https://github.com/mcchae/pytest-benchmark

KKimj commented 3 years ago

https://itkmj.blogspot.com/2019/12/python-pytest-unrecognized-arguments-n.html

$ pip install pytest-xdist

해결 되진 않음.

KKimj commented 3 years ago

pytest 의 버전이 python2 버전이다.

image

apt 로 pytest를 설치하면 안된다.

아래 설치 메세지는 올바르지 않다.

image

기존 pytest를 삭제한다. ( python2 제거와 pip를 pip3로 링크하는 것은 선택 사항)

$ sudo apt uninstall python-pytest

# 필요시에
$ sudo apt uninstall python2
$ sudo ln -sf /usr/bin/pip3 /usr/bin/pip

$ pip install pytest

# 아래 결과를 확인한다. (eg., pytest 6.2.2)
$ python -m pytest --version

image

example code에 아래 코드를 첫 줄에 추가한다.

https://pypi.org/project/pytest-benchmark/

import time

아래 코드를 저장하면 된다.

import time

def something(duration=0.000001):
    """
    Function that needs some serious benchmarking.
    """
    time.sleep(duration)
    # You may return anything you want, like the result of a computation
    return 123

def test_my_stuff(benchmark):
    # benchmark something
    result = benchmark(something)

    # Extra code, to verify that the run completed correctly.
    # Sometimes you may want to check the result, fast functions
    # are no good if they return incorrect results :-)
    assert result == 123

실행 방법

$ python3 -m pytest test.py

image

KKimj commented 3 years ago
import time 

def something(duration=0.000001):
    """
    Function that needs some serious benchmarking.
    """
    time.sleep(duration)
    # You may return anything you want, like the result of a computation
    return 123

def test_my_stuff(benchmark):
    # benchmark something
    result = benchmark(something)

    # Extra code, to verify that the run completed correctly.
    # Sometimes you may want to check the result, fast functions
    # are no good if they return incorrect results :-)
    assert result == 123

def test_my_stuff_different_arg(benchmark):
    # benchmark something, but add some arguments
    result = benchmark(something, 0.001)
    assert result == 123