jscholes, to python
@jscholes@dragonscave.space avatar

Needed to rename a test fixture in a file, and find/replace wasn't up for the job. So I decided to give 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 , 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.

SebastianM6L, to jenkins
@SebastianM6L@mastodon.social avatar

Anyone had an issue with from django.test import Client causing a high memory usage in a docker container?

I run the tests in a pipeline using a #jenkins agent in #docker.

When this test runs:

def test_login_user(self):  
 c = Client()  
 response = c.post('/user/login/', {'email': 'test1@test.de', 'password': 'test123'})  
self.assertEqual(response.status_code, 302)  

The memory usage goes thru the roof. Literally using up all memory until it crashes.

#django #pytest

adamchainz, to python
@adamchainz@fosstodon.org avatar

A #pytest pattern I’ve recently enjoyed using:

  1. Change some function in a way that needs fixes to call sites.
  2. Run the whole test suite with pytest.
  3. Copy the list of failing test IDs from pytest’s summary into a scratch file.
  4. Fix up the found callers.
  5. Verify everything fixed by saving the list of tests with: pytest $(cat scratch/testids.txt)

#Python #Testing

arildsen, to python
@arildsen@fosstodon.org avatar

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

SebastianM6L, to django
@SebastianM6L@mastodon.social avatar

Any cracks here who can explain me why when I run my tests with the django built in manage.py test (runs unittest) I have 51 tests run.

When I run them with pytest It will only run 38 tests.

hugovk, to python
@hugovk@mastodon.social avatar

Next month, @the_compiler is organising a pytest sprint in Austria, next to the Swiss border.

There's also a possibility for paid travel/accommodation.

See https://github.com/pytest-dev/sprint for more info and signup.

jtmoulia, to emacs
@jtmoulia@mstdn.social avatar

A guide on integrating + + using [mostly] builtin tooling and project local .dir-locals.el variables.

Specifically, this setup uses + for live syntax checking, for code running, for type-checking, and as the shell

Feedback would be welcome -- trying to get it robust + idiomatic.

https://jtmoulia.srht.site/guides/emacs-python-hatch/

HelenJoScott, to random
@HelenJoScott@mastodon.social avatar

Our pytest video series to learn how to combine and PyCharm has started so you can deliver quality code even faster. Watch now 📺 https://jb.gg/ls23kz 📺

Let me know what you think! 😀

adamchainz, to python
@adamchainz@fosstodon.org avatar

✍️ New post covering a “diffing” unit test in , which checks copy-paste-tweaked code is in sync with the upstream library.

I used this technique recently on a upgrade and I’m curious if anyone else has done similar.

https://adamj.eu/tech/2024/04/26/python-diffing-unit-test/

diazona,
@diazona@techhub.social avatar

@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? 🤔

jugmac00, (edited ) to random German
@jugmac00@fosstodon.org avatar

One of the best things about any conference... The hallway track.

@the_compiler, @jugmac00 and @ramgarlic chatting about @brianokken's book at in Berlin.

mgorny, to gentoo Polish
@mgorny@pol.social avatar

Ostatnio zastosowałem prostą sztuczkę w standardowej inwokacji PyTesta w , 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 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 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.

https://gitweb.gentoo.org/repo/gentoo.git/commit/eclass/python-utils-r1.eclass?id=1f35acddca01e91d4477f3d0340c47329517f474
https://bugs.gentoo.org/928411
https://github.com/ipython/ipython/commit/e27ee203ad54df0431d817abad09ec1caafde4d6
https://github.com/pytest-dev/pytest-asyncio/issues/810

opensuse, to devops
@opensuse@fosstodon.org avatar

Simplify your life! Discover how pytest_container can transform container testing process in this video. https://fosdem.org/2024/schedule/event/fosdem-2024-3747-testing-containers-with-python-and-pytest/

hugovk, to python
@hugovk@mastodon.social avatar

@coveragepy can now use Python 3.12's new sys.monitoring module with much lower overhead.

On 3.12, it's about the same as if you were running tests without coverage enabled!

https://nedbatchelder.com/blog/202312/coveragepy_with_sysmonitoring.html

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.

For example, @pillow is 9% - 27% faster!

https://github.com/python-pillow/Pillow/pull/7820

mblayman, to python
@mblayman@mastodon.social avatar

🐍 This 101 talk explains what automated tests are and how to get started with pytest for your projects. https://www.youtube.com/watch?v=etosV2IWBF0

SnoopJ, to random
@SnoopJ@hachyderm.io avatar

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.

https://git.snoopj.dev/SnoopJ/playground/commit/7a735adc9a2131fd8a51aaa78a734ffaeb3fffab

foxmask, to random French
@foxmask@framapiaf.org avatar

tuto with cool features by

kjaymiller, to python
@kjaymiller@mastodon.social avatar

folks

If you're stuck pinning pytest&lt;8.0 - There was a fork of pytest-lazy-fixtures that brings support.

https://github.com/dev-petrov/pytest-lazy-fixtures

kevinbowen, to python
@kevinbowen@fosstodon.org avatar

Hurrah for getting to 8.0.0!

Boo for it looking like the -sugar plugin breaking due to "PytestRemovedIn8Warning: The (startdir: py.path.local) argument is deprecated, please use (start_path: pathlib.Path)"

https://docs.pytest.org/en/latest/deprecations.html#py-path-local-arguments-for-hooks-replaced-with-pathlib-path

I'm not confident in my competance in fixing this issue; but, I guess I will try to poke around the plugin this week.

I like those little progress histograms, darn it...

diazona,
@diazona@techhub.social avatar

@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

diazona,
@diazona@techhub.social avatar

@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.

kevinbowen,
@kevinbowen@fosstodon.org avatar

@diazona

Thanks for looking at the issue.

shrug The pytest-sugar package is a wholly cosmetic dependency, so I have no issues moving forward with the upgrade to 8.0

I'll see what breaks this week, poke at the pytest-sugar code, and watch their progress...The least I can do is learn a bit more.

kevinbowen,
@kevinbowen@fosstodon.org avatar

Looks like pytest-sugar 1.0.0 was released about an hour ago. Thanks again @hugovk for noticiing my post & nudging the release along.

Much appreciated!
https://github.com/Teemu/pytest-sugar/releases/tag/v1.0.0

brianokken, to python
@brianokken@fosstodon.org avatar

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

brianokken, (edited ) to random
@brianokken@fosstodon.org avatar

--stepwise is the new -x

-x stop at the first failure
--stepwise first time, just like -x
--stepwise again, restart where we left off and continue until a failure.

nedbat, to random
@nedbat@hachyderm.io avatar

I think this 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?

EngineerDaryl, to python
@EngineerDaryl@fosstodon.org avatar

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.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • anitta
  • thenastyranch
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • ngwrru68w68
  • megavids
  • magazineikmin
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • provamag3
  • tester
  • Leos
  • JUstTest
  • All magazines