
johnp
Python Testing with pytest - Chapter 5 example c AttributeError: 'module' object has no attribute 'config'
Running the examples in chapter 5 c under pytest 5.4.1 causes an AttributeError: ‘module’ object has no attribute ‘config’.
In particular the code:
$ cd /path/to/code/ch5/c/tasks_proj/tests/func $ pytest --tb=no test_api_exceptions.py -k TestAdd
causes:
(bopytest) [user@computer func]$ pytest -v test_api_exceptions.py -k TestAdd ==================================================== test session starts ===================================================== platform linux -- Python 3.8.3, pytest-5.4.1, py-1.8.1, pluggy-0.13.1 -- /home/user/.local/share/virtualenvs/bopytest/bin/python cachedir: .pytest_cache rootdir: /home/user/Projects/bopytest/ch5/c/tasks_proj/tests, inifile: pytest.ini collected 9 items / 7 deselected / 2 selected test_api_exceptions.py::TestAdd::test_missing_summary PASSED [ 50%] test_api_exceptions.py::TestAdd::test_done_not_bool INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/_pytest/main.py", line 191, in wrap_session INTERNALERROR> session.exitstatus = doit(config, session) or 0 INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/_pytest/main.py", line 247, in _main INTERNALERROR> config.hook.pytest_runtestloop(session=session) INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__ INTERNALERROR> return self._hookexec(self, self.get_hookimpls(), kwargs) INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda> INTERNALERROR> self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall( INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/callers.py", line 208, in _multicall INTERNALERROR> return outcome.get_result() INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result INTERNALERROR> raise ex[1].with_traceback(ex[2]) INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/_pytest/main.py", line 272, in pytest_runtestloop INTERNALERROR> item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem) INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__ INTERNALERROR> return self._hookexec(self, self.get_hookimpls(), kwargs) INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda> INTERNALERROR> self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall( INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/callers.py", line 208, in _multicall INTERNALERROR> return outcome.get_result() INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result INTERNALERROR> raise ex[1].with_traceback(ex[2]) INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/_pytest/runner.py", line 85, in pytest_runtest_protocol INTERNALERROR> runtestprotocol(item, nextitem=nextitem) INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/_pytest/runner.py", line 100, in runtestprotocol INTERNALERROR> reports.append(call_and_report(item, "call", log)) INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/_pytest/runner.py", line 190, in call_and_report INTERNALERROR> hook.pytest_runtest_logreport(report=report) INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__ INTERNALERROR> return self._hookexec(self, self.get_hookimpls(), kwargs) INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda> INTERNALERROR> self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall( INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/callers.py", line 208, in _multicall INTERNALERROR> return outcome.get_result() INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result INTERNALERROR> raise ex[1].with_traceback(ex[2]) INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/_pytest/terminal.py", line 446, in pytest_runtest_logreport INTERNALERROR> res = self.config.hook.pytest_report_teststatus(report=rep, config=self.config) INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__ INTERNALERROR> return self._hookexec(self, self.get_hookimpls(), kwargs) INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda> INTERNALERROR> self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall( INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/callers.py", line 208, in _multicall INTERNALERROR> return outcome.get_result() INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result INTERNALERROR> raise ex[1].with_traceback(ex[2]) INTERNALERROR> File "/home/user/.local/share/virtualenvs/bopytest/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/home/user/Projects/bopytest/ch5/c/tasks_proj/tests/conftest.py", line 88, in pytest_report_teststatus INTERNALERROR> if report.failed and pytest.config.getoption("nice"): INTERNALERROR> AttributeError: module 'pytest' has no attribute 'config'
From the digging I have done it seems that the capability to do
pytest.config
from
pytest.config.getoption('nice'):
was deprecated in pytest 4.0 and removed from pytest 5.0.
What did work for me was:
def pytest_report_header(config): """Thank tester for running tests.""" if config.getoption("nice"): return "Thanks for running the tests." def pytest_report_teststatus(config, report): """Turn failures into opportunities.""" if report.when == "call": if report.failed and config.getoption("nice"): return (report.outcome, "O", "OPPORTUNITY for improvement")
Cheers
John
Most Liked

brianokken
Author of Python Testing with pytest
“nice” workaround, John.
2
Popular Pragmatic Bookshelf topics

Some minor things in the paper edition that says “3 2020” on the title page verso, not mentioned in the book’s errata online: p. 186 But...
New

Hi Brian, Looks like the api for tinydb has changed a little. Noticed while working on chapter 7 that the .purge() call to the db throws...
New

The following is cross-posted from the original Ray Tracer Challenge forum, from a post by garfieldnate. I’m cross-posting it so that the...
New

Hi Jamis, I think there’s an issue with a test on chapter 6. I own the ebook, version P1.0 Feb. 2019. This test doesn’t pass for me: ...
New

Hi @venkats, It has been mentioned in the description of ‘Supervisory Job’ title that 2 things as mentioned below result in the same eff...
New

This isn’t directly about the book contents so maybe not the right forum…but in some of the code apps (e.g. turbo/06) it sends a TURBO_ST...
New

I am working on the “Your Turn” for chapter one and building out the restart button talked about on page 27. It recommends looking into ...
New

In case this helps anyone, I’ve had issues setting up the rails source code. Here were the solutions: In Gemfile, change gem 'rails' t...
New

A Common-Sense Guide to Data Structures and Algorithms, Second Edition by Jay Wengrow @jaywengrow Hi, I have the paperback version of t...
New

Hi, I am getting an error I cannot figure out on my test. I have what I think is the exact code from the book, other than I changed “us...
New
Other popular topics

Algorithms and data structures are much more than abstract concepts. Mastering them enables you to write code that runs faster and more e...
New

Rust is an exciting new programming language combining the power of C with memory safety, fearless concurrency, and productivity boosters...
New

Do the test and post your score :nerd_face: :keyboard: If possible, please add info such as the keyboard you’re using, the layout (Qw...
New

Small essay with thoughts on macOS vs. Linux: I know @Exadra37 is just waiting around the corner to scream at me “I TOLD YOU SO!!!” but I...
New

The V Programming Language Simple language for building maintainable programs V is already mentioned couple of times in the forum, but I...
New

Think Again 50% Off Sale » The theme of this sale is new perspectives on familiar topics. Enter coupon code ThinkAgain2021 at checkout t...
New

Use WebRTC to build web applications that stream media and data in real time directly from one user to another, all in the browser. ...
New

This is going to be a long an frequently posted thread. While talking to a friend of mine who has taken data structure and algorithm cou...
New
New

This is cool! DEEPSEEK-V3 ON M4 MAC: BLAZING FAST INFERENCE ON APPLE SILICON We just witnessed something incredible: the largest open-s...
New
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /ruby
- /wasm
- /erlang
- /phoenix
- /keyboards
- /rails
- /python
- /js
- /security
- /go
- /swift
- /vim
- /clojure
- /emacs
- /haskell
- /java
- /onivim
- /typescript
- /svelte
- /c-plus-plus
- /crystal
- /kotlin
- /tailwind
- /react
- /gleam
- /ocaml
- /flutter
- /elm
- /vscode
- /ash
- /html
- /opensuse
- /centos
- /php
- /deepseek
- /zig
- /scala
- /textmate
- /lisp
- /sublime-text
- /nixos
- /debian
- /react-native
- /agda
- /kubuntu
- /arch-linux
- /django
- /ubuntu
- /revery
- /spring
- /manjaro
- /nodejs
- /diversity
- /lua
- /deno
- /julia
- /c
- /slackware