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

Question: refactoring to fully use pytest #272

Open
betaboon opened this issue Nov 25, 2024 · 20 comments
Open

Question: refactoring to fully use pytest #272

betaboon opened this issue Nov 25, 2024 · 20 comments

Comments

@betaboon
Copy link
Contributor

would you be interested in me refactoring the tests to fully and consistently use pytest?

i also have some ideas on how to get rid of the need to run docker compose.

@mindflayer
Copy link
Owner

What is the problem with using Docker Compose?

@betaboon
Copy link
Contributor Author

What is the problem with using Docker Compose?

you have to start it up manually before the tests. so running pytest is not sufficient.

@mindflayer
Copy link
Owner

mindflayer commented Nov 25, 2024

Back to the first question: the reason for having a mix of different types of tests - not 100% sure if it's still relevant - was that Mocket as a testing tool has to be compatible with any tool around, especially if it comes from the standard library. So, if some tests are relying on unittest, that's the reason behind.

@betaboon
Copy link
Contributor Author

to test for compatibility with pytest and stdlib.unittest maybe it would be good to cover that in dedicated tests?

@mindflayer
Copy link
Owner

mindflayer commented Nov 25, 2024

Mocket is not a framework people use to write software with. It's primarily a tool for testing, so tests are a first-class citizen in here, as important as the code itself.
This said, maybe show me an example of what you have in mind, but please don't get rid of the different cases (test-classes, test functions, implementing fixtures, based on unittest, async, etc). Every test was added to cover a specific use-case.

@betaboon
Copy link
Contributor Author

I'll leave tests exactly as they are then :)

regarding docker-compose.

  • for httpbin we could use httpbin directly (or pytest-httpbin, which triggered my question regarding switching fully to pytest, as pytest-httpbin also has support for https)
  • for redis we could use testcontainers-on-whales to spinup the container dynamically

@mindflayer
Copy link
Owner

mindflayer commented Nov 25, 2024

  • for httpbin we could use httpbin directly

That's was I used to do. I even tried other services similar to httpbin, the first I used. They are just not reliable enough to have a stable CI.

@betaboon
Copy link
Contributor Author

  • for httpbin we could use httpbin directly

That was I used to do, and I tried three different services - including httpbin -. They are just now reliable enough to have a stable CI.

Ah. I'm not talking about the service, but about the standalone Python package.

@mindflayer
Copy link
Owner

mindflayer commented Nov 25, 2024

The PyPI package is exactly what I use (through its Docker image): https://pypi.org/project/httpbin/

@mindflayer
Copy link
Owner

mindflayer commented Nov 25, 2024

If you are considering spawning the service from Mocket testing code, I believe it's way cleaner keeping the two things separated.
There is a Makefile that does all the magic, I don't think that adding more Python code for spawning a local server would help in any way.

@betaboon
Copy link
Contributor Author

ok i can live with that.
just fyi tho, i cannot use the makefile as it tries to patch the hosts-file in-place, which won't work on my system, as that file is immutable ;)

@mindflayer
Copy link
Owner

mindflayer commented Nov 25, 2024

Isn't fixing the Bash script easier? :)
Just open an issue and I'll fix it, if not.

@betaboon
Copy link
Contributor Author

"fixing" the bashscript wont do anything for me.
the way the tests are setup there are two requirements:

  • the containers are running
  • the hosts-file points certain domains to that container

conceptually that's impossible on systems like mine, where the hosts-file just cannot be changed.
so actually there is no fix for that.

which is what spinning the containers up from within python would be able to address, as both requirements would not be there anymore.

@mindflayer
Copy link
Owner

mindflayer commented Nov 25, 2024

What OS are you using? And how do you specify a new host pointing to a fixed IP?

@mindflayer
Copy link
Owner

which is what spinning the containers up from within python would be able to address, as both requirements would not be there anymore.

I still see simpler solutions, like using the IP of the container as a fall-back.

@betaboon
Copy link
Contributor Author

I'm on nixos, i have to configure it in my system-configuration which then generates the hosts-file.

but yeah, that's a me problem :P

@mindflayer
Copy link
Owner

mindflayer commented Nov 25, 2024

Using the hostname if we are able to add it, or the IP as a fall-back, should be enough.

@mindflayer
Copy link
Owner

I'm on nixos

Never ever tried that animal. :)

@mindflayer
Copy link
Owner

mindflayer commented Nov 25, 2024

It used to be possible to only run the tests relying on Mocket with make safetest, forgetting about real-socket ones. It looks like something changed in the Redis client, and it's now failing. It's worth investigating.

@mindflayer
Copy link
Owner

mindflayer commented Dec 21, 2024

FYI I have just fixed make safetest.

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