Skip to content

Conversation

@benoit-pierre
Copy link
Contributor

Change this into this.

@eli-schwartz
Copy link
Member

  • Isn't this generally supposed to be better handled with self.assert*() methods?

  • I'm not enthusiastic about adding a new file to the root of the repository. Is it possible to inject this for example by doing it in an if block inside unittests/__init__.py and still trigger the rewriting before pytest actually imports the files with the asserts that you want to rewrite? I haven't tested it but it seems plausible.

@benoit-pierre
Copy link
Contributor Author

benoit-pierre commented Aug 14, 2023

It's normally done automatically, but because of the way the testsuite is run and/or the way tests are named, it does not work.

  • Isn't this generally supposed to be better handled with self.assert*() methods?

Being able to just use assert is kind of one of the points in using pytest (why even bother with unittest?).

  • I'm not enthusiastic about adding a new file to the root of the repository. Is it possible to inject this for example by doing it in an if block inside unittests/__init__.py and still trigger the rewriting before pytest actually imports the files with the asserts that you want to rewrite? I haven't tested it but it seems plausible.

There's no corresponding config option, or command line argument. Doing it in conftest.py means it's automatically only done when running with pytest (if you want to keep compatibility with using unittest).

@eli-schwartz
Copy link
Member

Sorry, by if block I meant more a try block (conditional but a very different form of it).

try:
    import pytest
except ModuleNotFoundError:
    pass
else:
    pytest.register_assert_rewrite('unittests')

This should be harmless when running with unittest but still register the hook under pytest (while simultaneously avoiding the addition of "yet another repository root file").

@benoit-pierre
Copy link
Contributor Author

OK, I found a simpler alternative way.

@benoit-pierre benoit-pierre force-pushed the pr/fix_pytest_assertion_rewriting branch from 38decc3 to 132d6a7 Compare August 14, 2023 21:17
@benoit-pierre benoit-pierre force-pushed the pr/fix_pytest_assertion_rewriting branch from 132d6a7 to fc583a2 Compare August 14, 2023 21:18
@tristan957 tristan957 added this to the 1.3.0 milestone Aug 17, 2023
@eli-schwartz eli-schwartz merged commit 268276f into mesonbuild:master Aug 18, 2023
@benoit-pierre benoit-pierre deleted the pr/fix_pytest_assertion_rewriting branch August 18, 2023 09:52
@nirbheek nirbheek modified the milestones: 1.3.0, 1.2.2 Sep 6, 2023
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

Successfully merging this pull request may close these issues.

4 participants