Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting TypeError: 'NoneType' object is not Callable #258

Open
bab014 opened this issue Apr 19, 2024 · 2 comments
Open

Getting TypeError: 'NoneType' object is not Callable #258

bab014 opened this issue Apr 19, 2024 · 2 comments

Comments

@bab014
Copy link

bab014 commented Apr 19, 2024

First time user. Followed the instructions, I see that benchmark is an active plugin but everytime I try and use the benchmark fixture I get that error.

What am I doing wrong?

import csv

pytest_plugins = ("benchmark",)


def csv_ingest():
    with open("./data/customers-2000000.csv") as f:
        csv_reader = csv.reader(f)
        count: int = 0
        for record in csv_reader:
            # if count == 1:
            # print(record)
            new_record = record[0:4]
            name = new_record[2].upper()


def raw_ingest():
    with open("./data/customers-2000000.csv") as f:
        count: int = 0
        for line in f:
            record = line.split(",")
            # if count == 1:
            # print(record)
            new_record = record[0:4]
            name = new_record[2].upper()


def test_csv_ingest(benchmark):
    """
    Testing speed of initial ingest
    """
    benchmark(csv_ingest())


def test_raw_ingest(benchmark):
    """
    Testing speed of initial ingest
    """
    benchmark(raw_ingest())

And the full error

pytest
============================================================= test session starts ==============================================================
platform linux -- Python 3.11.2, pytest-8.1.1, pluggy-1.4.0
benchmark: 4.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /home/bret/repos/python/beamery
plugins: benchmark-4.0.0
collected 2 items                                                                                                                              

test_main.py FF                                                                                                                          [100%]

=================================================================== FAILURES ===================================================================
_______________________________________________________________ test_csv_ingest ________________________________________________________________

benchmark = <pytest_benchmark.fixture.BenchmarkFixture object at 0x7f3e66098e90>

    def test_csv_ingest(benchmark):
        """
        Testing speed of initial ingest
        """
>       benchmark(csv_ingest())

test_main.py:35: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.venv/lib/python3.11/site-packages/pytest_benchmark/fixture.py:125: in __call__
    return self._raw(function_to_benchmark, *args, **kwargs)
.venv/lib/python3.11/site-packages/pytest_benchmark/fixture.py:147: in _raw
    duration, iterations, loops_range = self._calibrate_timer(runner)
.venv/lib/python3.11/site-packages/pytest_benchmark/fixture.py:275: in _calibrate_timer
    duration = runner(loops_range)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

loops_range = range(0, 1), timer = <built-in function perf_counter>

    def runner(loops_range, timer=self._timer):
        gc_enabled = gc.isenabled()
        if self._disable_gc:
            gc.disable()
        tracer = sys.gettrace()
        sys.settrace(None)
        try:
            if loops_range:
                start = timer()
                for _ in loops_range:
>                   function_to_benchmark(*args, **kwargs)
E                   TypeError: 'NoneType' object is not callable

.venv/lib/python3.11/site-packages/pytest_benchmark/fixture.py:90: TypeError
_______________________________________________________________ test_raw_ingest ________________________________________________________________

benchmark = <pytest_benchmark.fixture.BenchmarkFixture object at 0x7f3e65fac5d0>

    def test_raw_ingest(benchmark):
        """
        Testing speed of initial ingest
        """
>       benchmark(raw_ingest())

test_main.py:42: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.venv/lib/python3.11/site-packages/pytest_benchmark/fixture.py:125: in __call__
    return self._raw(function_to_benchmark, *args, **kwargs)
.venv/lib/python3.11/site-packages/pytest_benchmark/fixture.py:147: in _raw
    duration, iterations, loops_range = self._calibrate_timer(runner)
.venv/lib/python3.11/site-packages/pytest_benchmark/fixture.py:275: in _calibrate_timer
    duration = runner(loops_range)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

loops_range = range(0, 1), timer = <built-in function perf_counter>

    def runner(loops_range, timer=self._timer):
        gc_enabled = gc.isenabled()
        if self._disable_gc:
            gc.disable()
        tracer = sys.gettrace()
        sys.settrace(None)
        try:
            if loops_range:
                start = timer()
                for _ in loops_range:
>                   function_to_benchmark(*args, **kwargs)
E                   TypeError: 'NoneType' object is not callable

.venv/lib/python3.11/site-packages/pytest_benchmark/fixture.py:90: TypeError
=========================================================== short test summary info ============================================================
FAILED test_main.py::test_csv_ingest - TypeError: 'NoneType' object is not callable
FAILED test_main.py::test_raw_ingest - TypeError: 'NoneType' object is not callable
============================================================== 2 failed in 5.78s ===============================================================
@ionelmc
Copy link
Owner

ionelmc commented Apr 20, 2024 via email

@bab014
Copy link
Author

bab014 commented Apr 20, 2024

Wow, so simple, can't believe I missed it. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants