Giter Site home page Giter Site logo

Comments (7)

la10736 avatar la10736 commented on September 25, 2024

Hi,
thank you to report it. Could you please post/link an example?

from rstest.

la10736 avatar la10736 commented on September 25, 2024

Maybe I don't understand your testcase... in la10736/rstest_issue2 seams to work as expected.... I missed something?

from rstest.

russel avatar russel commented on September 25, 2024

I do not have a trimmed down version to act as a test case – at least not yet, but I can try. The actual problem I have observed is with the tests for me-tv-schedule in the Me TV repository. https://github.com/Me-TV/Me-TV/blob/master/src/bin/me-tv-schedule.rs the #[rstest_parametrize] code compiles (if there is an error, it gets flagged so definitely being compiled) but is not actually run. The #[test] entries above are executed as normal.

I pulled the rs8080 project and ran it's tests and they work fine for me, but they are in src/ not src/bin/. The test cases you mention are all spawning a process to run the tests (I believe) and so are a somewhat different thing to what I have.

I have no idea what might be wrong, which is why it is so vexing.

from rstest.

la10736 avatar la10736 commented on September 25, 2024

Hi, maybe I got it. You cannot write arbitrary rust code in code annotation. To work around this limitation I used Unwrap("<some rust code>") syntax. So, try to change your code into:

    #[rstest_parametrize(
        datum, expected,
        case("2018-12-29T18:15:33", Unwrap("NaiveDate::from_ymd(2018, 12, 29).and_hms(18, 15, 33)")),
        case("2018-12-29 18:15:33", Unwrap("NaiveDate::from_ymd(2018, 12, 29).and_hms(18, 15, 33)"))
    )]
    fn parse_datetime_string(datum: &str, expected: NaiveDateTime) {
        match parse_to_datetime(datum) {
            Ok(result) => assert_eq!(result, expected),
            Err(e) => assert!(false,"failed to parse: {}", e),
        };
    }

As value in your test case you can use just direct value as numbers, bools and strings or if you need to write some rust statements use Unwrap("<code>") construct.

I know that Unwrap is not a good name but I didn't found any better one. Maybe I'll use a shorter one in the next version like r("<code>").

from rstest.

russel avatar russel commented on September 25, 2024

Aha, that was it. Works now. :-)

It is a shame having to put code as string since it is easy to put syntax errors in that are not checked by IDEs and compiler until test execution time. However, having parameterised tests is a huge saving in lack of boilerplate.

I did contemplate trying the "use a macro" technique of handling the boilerplate, but I really like pytest.mark.parametrize so went with rstest instead! I will be using this a lot, thanks for making it.

from rstest.

la10736 avatar la10736 commented on September 25, 2024

Next release will report errors like this and checks the Unwrap strings at compile time with readable errors.
For IDE highlight I hope to have some time to look in intellJ language injection to have it at least in IntelJ.

from rstest.

russel avatar russel commented on September 25, 2024

Having syntax checks early will be very helpful.

I use CLion for Rust (because of gdb support) rather than IntelliJ IDEA, but I think there is no difference for plugins. I guess contacting the Rust plugin team at JetBrains is a good first step?

from rstest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.