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

need help to understand documentation #316

Closed
ravi2k16 opened this issue Aug 8, 2020 · 8 comments · Fixed by #328
Closed

need help to understand documentation #316

ravi2k16 opened this issue Aug 8, 2020 · 8 comments · Fixed by #328
Labels

Comments

@ravi2k16
Copy link

ravi2k16 commented Aug 8, 2020

hi all,

Can any one explain me what are these tests files in tests dir of the source code ?
test_executor.py, test_janitor.py, test_noopexecutor.py

what is executor, janitor and noopexecutor? how can some one use these features in his testing?

I have used factories.postgresql_proc() and factories.postgresql() in my trial project and it is working fine. But not sure about
others. I find little difficult to understand the documentation as a pytest newbie.

-Thanks

@rickwargo
Copy link

  1. Executor is responsible for starting up and tearing down a local PostgreSQL instance.
  2. Janitor is responsible for encapsulating the database activity through Executor. It provides a new database and a connection to that database for testing.
  3. noopexecutor is an Executor for an existing database. It is used when there are tests that do not require a database connection for assertions.

That being said, I also do not understand noopexecutor. I would like to get a connection to an existing database so that I can run tests that check the structure/schema of the existing database. I would also like to run data-centric tests on pre-existing data. Can noopexecutor do that?

@fizyk
Copy link
Member

fizyk commented Aug 17, 2020

@rickwargo actually the noopexecutor is an executor that does nothing more than providing connection details to the existing postresql server for client fixture. So you still can use it in tests that do require assert on the database state.
Speaking of it further the schema still will be created from scratch each time and after each test it'll be cleared.

If you want to run test on pre-existing data, you need to create a fixture that will populate the database with the data. Otherwise you risk tests meddling with other tests.

@fizyk fizyk added the question label Aug 17, 2020
@dazza-codes
Copy link

Please enhance documentation with examples of how to use factories and the janitor in the context of actual test fixtures and tests, not just how to use the classes or methods with no test context.

@akaihola
Copy link

akaihola commented Sep 8, 2020

I guess one should just use psycopg2 or whatever PostgreSQL client library in tests. This should be pointed out in the documentation, preferably with a practical example.

@fizyk
Copy link
Member

fizyk commented Sep 8, 2020

@akaihola the basic postgresql fixture returns already configured connection. I've added hopefully better explanation to readme, however I've been using the code for so long, that it becomes obvious for me, and it's always hard to explain something obvious.

Thank You guys for triggering me to bend my mind around the issue :) If you'll have more those obvious-not-obvious issues found, please let me know! :)

fizyk added a commit that referenced this issue Sep 8, 2020
Enhanced readme about postgresql fixture. refs - #316
@jcpunk
Copy link
Contributor

jcpunk commented Sep 10, 2020

Another useful example might be: How would I extend the postgresql fixture with a local fixture so that it loads my database schema automatically?

@fizyk
Copy link
Member

fizyk commented Sep 11, 2020

@jcpunk apart from your feature, maybe I could link/copy example from other places like https://github.com/fizyk/pyramid_fullauth/blob/master/tests/conftest.py#L35 🤔

@jcpunk
Copy link
Contributor

jcpunk commented Sep 11, 2020

I'll confess, as someone who is not good at pytest, the more code samples I can see and "paraphrase" to get what I'm looking for the happier I am.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants