Needed to rename a test fixture in a #Python file, and find/replace wasn't up for the job. So I decided to give #VSCode a go:
I started by pressing Ctrl+F2, for "Change All Occurrences". I think that is basically find/replace, and hence didn't do what I wanted.
Instead, I installed the recommended Python extension, and pressed F2 for "Rename Symbol". That claims to have only made one change, and the references to the function are still using the old name.
So, consider me confused. I'm using #pytest, whereby the test fixtures are referenced as function arguments rather than being called directly. Maybe that's what VS Code is struggling with? Either way, I've now spent more time on this than just manually editing the text.
I have used numpy.allclose to test for approximate equality in Python for years, but I recently found pytest.approx better, because it lets Pytest interpret the result. For example, with numpy.allclose:
> assert np.allclose(result, 3.061, atol=1e-3, rtol=1e-3)
E assert False
E + where False = <function allclose at 0x7f8fea7efa60>(1.4872, 3.061, atol=0.001, rtol=0.001)
E + where <function allclose at 0x7f8fea7efa60> = np.allclose
Our pytest video series to learn how to combine #pytest and PyCharm has started so you can deliver quality code even faster. Watch now 📺 https://jb.gg/ls23kz 📺
@adamchainz Neat, this is one of those things that seems like it should normally come with a disclaimer "for entertainment value only, do not use", but on the rare occasion that you need it....
I wonder if there's a better way to present the diff of diffs that could be built into a custom output hook? 🤔
Ostatnio zastosowałem prostą sztuczkę w standardowej inwokacji PyTesta w #Gentoo, by rzucało błąd, kiedy wykryje nieużywane funkcje async. Miało to na celu zwiększenie szansy zauważenia, jeśli w którejś paczce przypadkiem pominięto zależność od dev-python/pytest-asyncio (albo równoważnej wtyczki), albo przy wyłączonym automatycznym ładowaniu wtyczek, pominięto ładowanie takiej wtyczki.
Dziś otrzymałem pierwsze zgłoszenie, dotyczące paczki dev-python/ipython. Przeszukałem źródła, i potwierdziłem zależność — tyle, że z jakiegoś powodu przypiętą do wersji < 0.22. No cóż, nie mamy już takiej, ale warto sprawdzić, czy mimo to nie zadziała. Tak więc dodałem zależność, dodałem -p asyncio… a #PyTest dalej jej nie widzi. Podrapałem się po głowie, spróbowałem PYTEST_PLUGINS — dalej nie działa. Co do…?
Tak więc sklonowałem repozytorium git, spróbowałem ze starszą wersją wtyczki — testy działają. Zaktualizowałem do 0.23.6, przestały działać. Sprawdziłem historię, i okazało się, że starą wersję wymuszono ze względu na błąd w wydaniu 0.22.0. Tyle że ten błąd już poprawiono, wydanie usunięto, a mój problem był zupełnie inny.
Przyjrzałem się sprawie bliżej. Z jakiegoś powodu, w kodzie #IPython testy nie są bezpośrednio oznaczone markerem pytest.mark.asyncio. Zamiast tego, conftest.py automatycznie dodaje ten marker do wszystkich testów, będących współprogramami. Ze starszymi wersjami to działało, z nową przestało. Wygląda na to, że test zostaje poprawnie oznaczony, ale wówczas przestaje być rozpoznawany jako współprogram. Przygotowałem minimalny przykład i zgłosiłem problem.
Istotne w tej historii jest to: (potencjalny) problem nie został zauważony przez dłuższą chwilę, bo autorzy IPythona przedwcześnie wymusili starą wersję ze względu na chwilowy błąd, a następnie nie usunęli tego ograniczenia.
With 7.4.2, you can set COVERAGE_CORE=sysmon globally on your CI, and it'll only use it where available (Python 3.12 and 3.13 alpha), and use the default for 3.11 and older.
#pytest is such a nice library. The pytest_addoption(parser) hook speaks argparse pretty naturally, so you can pass action=argparse.BooleanOptionalAction instead of action="store_true"
This option (new in Python 3.9) gives you a pair of feature flags (i.e. --feature/--no-feature) for free.
Boo for it looking like the #pytest-sugar plugin breaking due to "PytestRemovedIn8Warning: The (startdir: py.path.local) argument is deprecated, please use (start_path: pathlib.Path)"
@kevinbowen Seems like a straightforward thing to fix, though, isn't it? Just gotta switch from py.path.local (which AFAIK ha been at least "unofficially deprecated" for a long time) to pathlib.Path
@kevinbowen Oooh, okay I think some fishy stuff is going on here. Just based on a quick look at the PR linked from that issue, it kind of looks like the issue has not been fixed and the owner was wrong to close the issue - but I also kind of suspect the proposed fix may not be correct, and if they ran a type checker on the code it would probably tell them why.
This is, of course, without knowing anything about pytest-sugar and its code base, so I could be entirely wrong. Just saying, at first glance, I agree that it looks sketchy.
I'm sure they'll figure it all out at some point though. If nothing else, after the next version of pytest gets released and things start breaking.
Instead of adding a timeout to pytest-repeat, I built a small plugin just for the suite-timeout functionality: pytest-suite-timeout
It aborts a test run between tests if a timeout expires
Works great with pytest-repeat, but also can be used anywhere. https://github.com/okken/pytest-suite-timeout #Python#pytest
I think this #pytest plugin exists, but I can't find it: run just 20 randomly selected tests from my test suite.
I don't need splitting into groups, I don't need "the whole suite but in a random order". How can I run a randomly selected subset of my tests?
Gifted myself the book about PyTest by @brianokken (because I was not busy enough with all of my personal projects 😂 ). Hope this test doesn't fail: assert is_good_book.